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
himabatavia
Courses Plus Student 561 PointsCrystal Ball Button Error
I have an error in MainActivity.xml, under mGetAnswerButton = (Button) findViewById(R.id.button1);
The error says:
Multiple markers on this line:
- button 1 can not be resolved and is not a field
- linebreakpoint: mainactivity [line 30, onCreate(Bundle)
How do i fix this?
1 Answer
Daniel Hartin
18,106 PointsHi Hima
The line of code you have posted appears correct, there are 4 things to check.
Make sure you have imported android.widget (just press Ctrl + Shift + O, if using eclipse).
The code snipet above does not declare your variable so make sure somewhere before this line is executed you have the code Button mGetAnswerButton;
Make sure your XML file changes are saved before referencing them in JAVA code and if necessary rebuild/clean the project to make sure everything is updated.
Lastly (and most importantly) make sure in your XML layout file you have a Button element with the id button1. It should look something like this:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap content"
android:id="@+id/button1"/>
I hope after checking these 4 things you resolve your error, however if you are still having problems please paste all your Java and XML code and I will be happy to take a look.
Daniel
Justin Horner
Treehouse Guest TeacherJustin Horner
Treehouse Guest TeacherHello Hima,
Are you still having problems? I'd be glad to help if you're still stuck :)