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 trial

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Introducing String Resources

The value "Friend" assigned to 'name' is never used.

How do i fix?

package com.example.jacob.interactivestory;

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem;

public class StoryActivity extends Activity {

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();
    String name = intent.getStringExtra(getString(R.string.key_name));

    if (name == null) {
       name = "Friend";
    }
        Log.d(TAG, "name");
}

}

//the second name in the if line shows gray

1 Answer

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hello,

Your IDE (I'm assuming Android Studio) is just letting you know that you assign the value "Friend" to the variable name, but you don't use it anywhere... you aren't setting it in a TextView, using it in a method, etc. This is not an error. It's just a nice little message to let you know that you have a variable that you are not yet using. Later on when you do something with the 'name' variable, that message will go away.

As a side note in your Log statement.. it should be:

Log.d(TAG, name);

thanks