Take the 2-minute tour ×

In the main.xml i have :

        android:text="Your total is 0" 
        android:layout_gravity ="center"
        android:gravity = "center"
        android:text = "+"
        android:textSize = "20dp"

        android:text = "-"
        android:textSize = "20dp"

And in the main body i have:

public void onCreate(Bundle savedInstanceState) {
        counter = 0;
        add = (Button) findViewById(R.id.bAdd);
        sub = (Button) findViewById(R.id.bSub);     
display = (TextView) findViewById(R.id.tvDisplay); 

It cites the (R.id.bAdd/Sub/Display) that it cannot be resolved or is not a field. I've been following a youtube guide on how to do this exactly, so i'm confused as to how i have an error, and how i correct it.

share|improve this question

2 Answers 2

R.java is extremely finicky in Eclipse. If you haven't tried cleaning the project, restarting Eclipse, etc, try that. Is R.java found in your gen folder? Are other variables that should be found in R also unable to be resolved or are those the only ones? If all else fails you can try deleting R.java and cleaning the project, and assuming your XML doesn't contain errors it should re-generate.

share|improve this answer
I'm not seeing an R.java file in my gen folder, and those are the only variables i have in my project so far. I'm new at this so i'm not sure how you'd clean it since it's as basic as it can get for me. –  Matt Smith Apr 4 '12 at 19:52
If gen > your.package.name > R.java is not there, then that explains why those variables are throwing errors. Click your project on the left and then go to Project > Clean, on the top of the screen/window. If R.java isn't generated than your xml has an issue or there's another underlying error in your Android project. –  Chris Apr 4 '12 at 20:00
Okay, i found R.java. Tried cleaning my project, but no go. –  Matt Smith Apr 4 '12 at 20:26
If R.java doesn't contain the variables that can't be resolved, then you'll have to delete it and clean. Make sure there aren't any errors or warnings in your project, especially in the xml. If it still doesn't work after a few attempts you may have to restart Eclipse and try again. Unless there's a missing piece of the puzzle here I'll bet it's Eclipse, well, being Eclipse. –  Chris Apr 4 '12 at 20:32
I do have an error in my XML. android:text = "+" And the error is "Hardcoded String "+", should use @string resource." R.java contains a line about the variables i'm looking for, though, so i assume it's safe. –  Matt Smith Apr 4 '12 at 20:38

Check to see if java.R is being imported at the top of the .java file where you're having the issues. None of the other solutions worked for me, but this did. If it is being imported, you should have a yellow warning. Remove the line, and don't import it.

share|improve this answer

Your Answer


