Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKate Dougherty
8,334 Points"operator || cannot be applied to 'null', boolean'" error
Hi,
I'm getting an "operator || cannot be applied to 'null', boolean'" error on the check for a null/empty name. Here's my code:
package com.katedoughertywriter.interactivestory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
public class StoryActivity extends AppCompatActivity {
// Create a tag that will show the name of the class in the Android Monitor log (called below)
public static final String TAG = StoryActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story);
Intent intent = getIntent();
// Get the name the user passed in from the MainActivity intent
// which is stored as a string in resources/strings.xml
String name = intent.getStringExtra(getString(R.string.key_name));
//Check if name is null (user typed nothing) or if it's empty (user typed a space or empty string)
if (name === null || name.isEmpty()) {
name = "Friend";
}
// Create log in Android Monitor to make sure that the new name is now available
// in this activity
log.d(TAG, name);
}
}
1 Answer
Ben Deitch
Treehouse TeacherHey Kate! It looks like you've got an extra equals sign in your if statement. It should just be:
if (name == null ...