Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

"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
STAFF
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 ...