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!

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

This video put errors in my code all over the place

I've been following the videos close to exactly, and when I entered the code Ben enters here in the MainActivity file, Android studio put up all sorts of errors. I did seem to notice some difference on the collapsed part at the beginning, and I'm wondering if that's it, but I'm not sure here.

Here is my code:

package ameydharden.interactivestory;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {

    private EditText mNameField;
    private Button mStartButton;

    protected void onCreate(Bundle savedInstanceState) {

        mNameField = (EditText)findViewById(R.id.nameEditText);
        mButton = (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();

1 Answer

Cooper Craig
Cooper Craig
2,104 Points

I think your problem might be you declared a value for mButton but it should be mStartButton

Try that out.