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

Henry Gines
1,365 PointsHow to initialize the showFactButton variable using the findViewById() method.
Android Development Challenge task 1 of 1 How to initialize the showFactButton variable using the findViewById() method like the TextView above it. The ID for the button is showFactButton, and don't forget to cast it to a Button with (Button)!
Here is what I wrote:
// Declare our View variables and assign them the Views from the layout file
TextView factLabel = (TextView) findViewById(R.id.factTextView); Button showFactButton= findViewById(R.id.showFactButton);
But there is one error in output.html ./FunFactsActivity.java:16: incompatible types found : android.view.View required: android.widget.Button Button showFactButton= findViewById (R.id.showFactButton); ^ 1 error Any suggestion to solve this 1 error? Thanks in advance.
4 Answers

Tom Mertz
15,254 PointsHey Beau,
It looks like you forgot to typecast your button. Try adding (Button) before your findViewById of your fact button.
Let me know if you get it working.

Henry Gines
1,365 PointsHi Tom, Thanks in a million times. It worked and I really appreciate your help.

Tom Mertz
15,254 PointsNo problem, glad you got it working!

ISAIAH S
1,409 PointsHi Beau,
You might want to add
```.java
before your code and three more backticks after it. (a backtick is not a ' but a `. they are usually found under a ~ on a keyboard.)

steve kevin arias serrano
9,037 PointsButton showFactButton = (Button) findViewById(R.id.showFactButton);

pankaj kumar
Courses Plus Student 367 Points./FunFactsActivity.java:17: error: variable factLabel is already defined in method onCreate(Bundle) TextView factLabel = (TextView) findViewById(R.id.factTextView); ^ ./FunFactsActivity.java:18: error: variable showFactButton is already defined in method onCreate(Bundle) Button showFactButton; ^ 2 errors
How to solve this error?