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 Build a Simple Android App with Java Basic Android Programming Initializing a Button

Initialize the showFactButton variable using the findViewById() method like the TextView above it. The ID for the button

what is the correct answer mine is wrong, and is pointing at shawfactbutton pointing at the "s"

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 {

    public void onCreate(Bundle savedInstanceState) {

        Button showFactButton = (Button) findViewById(R.id.showFactButton);
        TextView factLabel = (TextView) findViewById(R.id.factTextView);
        Button showFactButton;


1 Answer

Hi Farai. The solution for this challenge was posted in your other post. But let's have a look at the problem here, just so you know. When clicking on Preview, you see:

./FunFactsActivity.java:18: error: variable showFactButton is already defined in method onCreate(Bundle)
        Button showFactButton;
1 error

It says "error: variable showFactButton is already defined in method onCreate(Bundle)" If you look at the code, you will see that Button showFactButton is indeed defined twice in the code:

Button showFactButton = (Button) findViewById(R.id.showFactButton);  // Defined here
TextView factLabel = (TextView) findViewById(R.id.factTextView);
Button showFactButton;  // Defined here

Just remove the last line (Button showFactButton;) and you'll be fine. Hope that helps :)

thanks a lot it helped, others will actually add more confusion