This question already has an answer here:
-
Developing for Android in Eclipse: R.java not regenerating
64 answers
Ive just joined StackOverflow because I just cant find any answers to my problem. :(
I have however found other threads on this, and none seem to fix it.. i have no idea why.
So basically, i am trying to make an android app, i start up a NEW project and already the R.Java is missing (causing major issues, and i can't even compile from it :( ), ive tried: import.android.R;
, import.(packagename).R;
, ive tried to "clean"
it, and a bunch of other stuff. Literally everything i can think of.
What is going on, and how can I fix this?
package com.nicco.compare;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
R.java is auto generated.
1. Do you have a import statement like import android.R;. If so remove the import
2. Do you have errors in your xml files. If so fix them
3. Clean and build project.
My guess your are importing android.R
Remove this import statement(import android.R;
). Clean and build you project. this should solve your problem.
Right Click on project goto properties choose android on the left. Check you have the right version checked.
Also look for the sdk version in manifest file
Here's how I fixed this in Eclipse:
Create R.java in gen folder manually and save.
After that go to Project and click "Clean"
The following message will display and your file will automatically be rewritten:
R.java was modified manually! Reverting to generated version!
This is alternate approach
R is an automatically generated class that holds the constants used to identify your >resources. If you don't have an R.java file (it would be gen/com.techfuze.app_name/R.java in >Eclipse with the 1.5 SDK) I would recommend closing and reopening your project or going to >Project > Build all (and selecting "Build Automatically" while there as recommended by >Josef). If that doesn't work than try making a new project, if the problem is recreated than >post here again and we'll go into more detail.
but I've found out that there was another problem that was causing the first one. The tools in the SDK directory didn't have the permissions to be executed, so it was like the didn't exist for Eclipse, thus it didn't build the R.java file.
So modifying the permission and selecting "Build Automatically" solved the problem.
try this one ,first "right click" the "project" and than go for the "properties" and select "java build path" and than select "version checkbox" and save changes.
and if it is not working than close your all files and clean the project........
Try to verify that your layout files (i.e) the xml files don't have any error in them. Because R.java will be generated only when.xml files are clean
It happened to me when I added a search action but failed to add the search string in values/strings.xml
. I then did a clean and the R.java
disappeared. Once I added the string, the build succeeded and regenerated the R.java
.