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

Justin Sparks
Justin Sparks
4,148 Points

TAG is causing an error

When I type TAG within the parenthesis of Log.d(), TAG shows up in red and when I hover over it with the mouse, it says "'TAG' has private access in 'android.support.v4.app.FragmentActivity'". I am not sure what that means. Please help!

4 Answers

Stone Preston
Stone Preston
42,016 Points

you are missing the line of code that sets the tag variable. also looking at the video your class has the wrong super class. It should inherit from Activity not ActionBarActivity so you will need to change that (the part that comes after extends)

//change the super class to Activity
public class StoryActivity extends Activity {

    //add the tag 
    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("name");

        if(name == null) {
            name = "Friend";
        }
        Log.d(TAG, name);
    }
}
Igor Demchenko
Igor Demchenko
1,433 Points

Can you help me with my code:

import android.app.Activity; import android.content.Intent; import android.support.v7.app.ActionBarActivity; 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("name");

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

}

I checked it line by line and it's identical. Also tried deleting and retyping, nothing works: if(name == null){ --- if unexpected token; name unknown class name, == name unepected token; name == "Friend"; } --- all not a statement Log.d(TAG, name); d can not resolve symbol, TAG, name unknown class name

I have substituted everything with you code - errors go away. So, I am just woundering here what is wrong?

Justin Sparks
Justin Sparks
4,148 Points

It worked! Thanks a lot, I don't know how I missed all of that.

Stone Preston
Stone Preston
42,016 Points

no problem glad its working

Stone Preston
Stone Preston
42,016 Points

post your code please. does your line of code where you define TAG begin with public or private? it should be public

Justin Sparks
Justin Sparks
4,148 Points

package com.example.user.interactivestory;

 import . . .

public class StoryActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);

    Intent intent = getIntent();
    String name = intent.getStringExtra("name");

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

}

This is my code for StoryActivity.java