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;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 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;

            @Override
            public void onClick(View v) {

                String[] facts;
                        "Are you still here?",
                        "Huh.",
                        "This is decently random",
                        "Idiot",
                        "I dont like you",
                        "I am a BULLY",
                        "BBBBRRRRRAAAAA",
                        "Why ya hitting yourself",
                        "Nullable",
                        "Loading...",
                        "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
                mFactTextView.setText(fact);

            }
        };
       mShowFactButton.setOnClickListener(Listner);
    }
}

1 Answer

Fahad Mutair
Fahad Mutair
10,342 Points

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

String[] facts = {