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

Jude Dugbere
Jude Dugbere
1,211 Points

R.string. is not popping out the key_name,.. and if i enter it displays red

private void startStory(String name) { Intent intent = new Intent(this, StoryActivity.class); intent.putExtra(getString(R.string.), name); startActivity(intent); }

9 Answers

Jude Dugbere
Jude Dugbere
1,211 Points

<?xml version="1.0" encoding="utf-8"?> <resources>

<string name="app_name">Interactive Story</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_story">StoryActivity</string>
<string name="key_name">name</string>
<string name="name_key">name</string>

</resources>

am now using the "name_key" which works for me

Sorry I wasn't able to help figure this out for you. You might want to mark your answer as being the best answer so that people know this at least has been resolved.

Hello,

Without seeing the full code(which is typically very helpful in finding issues), I can only make a few guesses. First, you haven't completed the id, leaving it at R.string. instead of R.string.string_id. The other possibility that I can think of is that you're using subpackages and need to import your R class(do note that the R class is generated automatically). If R is underlined, please select it, hit Alt + Enter, then select import class. Please let us know if these solved your problem or if you need more assistance. If you do need more assistance, please provide your updated code so that we can see where any more issues could be coming from.

Jude Dugbere
Jude Dugbere
1,211 Points

public class MainActivity extends Activity {

private EditText mNameField;
private Button mStartButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNameField = (EditText) findViewById(R.id.namEditText);
    mStartButton = (Button) findViewById(R.id.startButton);

    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String name = mNameField.getText().toString();
            startStory(name);

        }
    });
}
    private void startStory(String name)
    {
        Intent intent = new Intent(this, StoryActivity.class);
        intent.putExtra(getString(R.string.key_name) name);
        startActivity(intent);
    }

}

this is the full code

Do you have any lines starting with "package" or "import"? Those might help track down what's wrong.

Jude Dugbere
Jude Dugbere
1,211 Points

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText;

here is my import

Jude Dugbere
Jude Dugbere
1,211 Points

these are my import files

Jude Dugbere
Jude Dugbere
1,211 Points

package com.example.jude.interactivestory;

this also my package

Jude Dugbere
Jude Dugbere
1,211 Points

Am working on Build interactive Story app

Not looking like there's much wrong so you can always try the old, "Clean and rebuild the project" approach. To do this, go to Build, then select Clean Project. Then select Build, then Make Project. That tends to clear up problems like that with no obvious cause. Sometimes people have to also try File, Invalidate Caches/Restart. Please let us know if this helps. If not, we can try a few other things.

Jude Dugbere
Jude Dugbere
1,211 Points

no its still not working. i tried adding another string to the string.xml which i named "name_key" it popped out but why this "key_name is not popping out that i dont understand

Could you post your string.xml file?

Jude Dugbere
Jude Dugbere
1,211 Points

thanks for your help. alright