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) User Input Getting Text from an EditText

can't start the app because "cannot resolve symbol NameEditText" mNameField = (EditText)findViewById(R.id.nameEditTex

package me.mars;

import android.app.Activity; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;

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.nameEditText);
    mStartButton = (Button)findViewById(R.id.startButton );

    mStartButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String name = mNameField.getText().toString();
            Toast.makeText(MainActivity.this, name, Toast.LENGTH_LONG).show();
        }
    });

}

}

Vrezh Gulyan
Vrezh Gulyan
11,161 Points

I had the same problem as you and I figured it out! instead of actually typing out the word Button and EditText just start typing them and then click on Button for autocompletion. Next to that option it'll say android widget. Weird that it makes a difference but that'll solve your problem.

2 Answers

Hi,

Somewhere in one of your application's layout resources (those XML files that describe your UI) you must define an EditText control and set it's id attribute to nameEditText. Something like:

<EditText
    android:id="@+id/nameEditText"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

Hope this helps.

Thanks Andrei, but this seems like a bug in Android Studio