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
Nancy Melucci
Courses Plus Student 36,659 PointsAndroid Studio added code now I can't run the new fact.
I was following Ben's lesson accurately, then I tried to run the new fact and Studio threw an error. I looked at the Java code and it appears to have added some things. I can't really explain without showing it. I think it's the private static final R =; All the Rs are red now. Thanks...Nancy Melucci
package com.neo.nancy.funfacts;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FunFactsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
//declare our view variables and assign them Views from the layout file
final TextView factLabel = (TextView) findViewById(R.id.factTextView);
final Button showFactButton = (Button) findViewById(R.id.showFactButton);
final View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
//The button was clicked to present a new fact
String fact = "Ostriches can run faster than horses.";
factLabel.setText(fact);
}
};
showFactButton.setOnClickListener(listener);
}
3 Answers
Steve Hunter
57,712 PointsThe private static final R = line is doing nothing - delete it and then we can start working out if there's any other problems.
Nancy Melucci
Courses Plus Student 36,659 PointsOK, I did that. Waiting for your advice. Thanks.
Steve Hunter
57,712 PointsOK - so the code won't compile as the lines with R in them are showing an error? If you hover over it, does it say it can't resolve the symbol?
Hmm ... that's odd. I'd try Project | Clean Project ...
Then have a go at File | Invalidate Caches / Restart ...
I'll have a look at other options too.