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 trialEleni Minadaki
3,687 PointsCompiler error on Stage 3,Build a simple android app
Button showFactButton = (Button)findViewById(R.id.showFactButton); Button showFactButton;
Could anyone see where is the problem here? Thanks a lot!
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FunFactsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
// Declare our View variables and assign them the Views from the layout file
Button showFactButton = (Button)findViewById(R.id.showFactButton);
Button showFactButton;
}
}
4 Answers
Jasmine Leon
8,098 PointsIt means that you can't declare a variable twice or more in the same scope. You need to either have:
- Button showFactButton = (Button) findViewById(R.id.showFactButton); or
- Button showFactButton; in the onCreate method, but not both.
Does that help?
Jasmine Leon
8,098 PointsYou should remove the second declaration of the showFactButton.
Eleni Minadaki
3,687 PointsThanks for your reply Jasmine Leon i write this:Button showFactButton = (Button) findViewById(R.id.showFactButton); Button showFactButton; and the error is this! FunFactsActivity.java:16: error: variable showFactButton is already defined in method onCreate(Bundle) Button showFactButton; it look like the error is the showFactButton but can't understand what it means!
Eleni Minadaki
3,687 PointsNow it is very understandable for me,thank you very much for your help! apreciate!