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.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(;
        mShowFactButton = (Button) findViewById(;

        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,354 Points

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

String[] facts = {