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 trialNyle Cohen
448 PointsErrors 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
10,359 Pointshi Nyle Cohen , you have error at this line String[] facts; it should be
String[] facts = {