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!

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 Basic Android Programming Making a Button Do Something

Nyle Cohen
Nyle Cohen
448 Points

Errors in my code

package com.teamrandom.therandomapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    // Declare our view variables.
    private TextView mFactTextView;
    private Button mShowFactButton;

    protected void onCreate(Bundle savedInstanceState) {

        // Assign the views from the layout files to the corresponding variables
        mFactTextView = (TextView) findViewById(R.id.textView);
        mShowFactButton = (Button) findViewById(R.id.ShowFactButton);

        View.OnClickListener listener = new View.OnClickListener() {
            public Object facts;

            public void onClick(View v) {

                String[] facts;
                        "Are you still here?",
                        "This is decently random",
                        "I dont like you",
                        "I am a BULLY",
                        "Why ya hitting yourself",
                        "Apple = Loners",
                        "Blokin out the haters :)",
                        "Spotify = FUTURE",
                        "I am a football player" };
                //The button was clicked, so update the facttext view with a new fact.

                String fact = "";
                // Randomly select a fact
                Random randomGenarator = new Random();
                int RandomNumber = randomGenarator.nextInt(14);
                fact = facts[randomNumber];
                // Update the screen with our dynamic Fact


1 Answer

Fahad Mutair
Fahad Mutair
10,359 Points

hi Nyle Cohen , you have error at this line String[] facts; it should be

String[] facts = {