Android Build an Interactive Story App Intents and Multiple Activities Getting Resources from the Context

"operator || cannot be applied to 'null', boolean'" error


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.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();

    protected void onCreate(Bundle savedInstanceState) {

    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
Ben Deitch
Treehouse Teacher

Hey Kate! It looks like you've got an extra equals sign in your if statement. It should just be:

if (name == null ...