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

mStartButton Unknown class error

package com.example.eric.interactivestory;

import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; I dont know what i done wrong can someone check my code and see my mStartButton gives me a Unknown Class error

import android.view.MenuItem; import android.widget.Button; import android.widget.EditText;

public class MainActivity extends ActionBarActivity { 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);

Is your start button name StartButton or startButton? just at first glance I'll look up the the code I had in a sec :)

Cheers! Stephen

Here what I have for that block..

 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() {
            @Override
            public void onClick(View v) {
                String name = mNameField.getText().toString();
                startStory(name);
            }
        });

1 Answer

Eric, Looks like the statement is outside of the bracket

} mStartButton = (Button)findViewById(R.id.StartButton);

try

mStartButton = (Button)findViewById(R.id.StartButton); }

Thank you David it worked!

Awesome glad I could help.