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 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.