1

I have freshly installed eclipse 3.8 and android sdk. When I create a new project I get error R cannot be resolved to a variable in MainActivity.java. R.java is missing and instead I have BuildConfig.java in gen folder. Based on suggestions given on similar questions I tried followings but no success.

  1. Reinstalled ADT
  2. Cleaned the project
  3. Restart eclipse

Kindly help.

3
  • 6
    Has one of your xml files an error? If so, R will not be generated. Commented Feb 1, 2013 at 19:08
  • Is there an R.java in your project folder? this can help tell us whether the file isnt there or whether it is there and you are having a pointing proplem to it. Commented Feb 1, 2013 at 19:13
  • same problem here, errors in your xml , even appmanifest file and R is not generated. Commented Feb 28, 2014 at 18:50

6 Answers 6

3

Yes, XML files may be the culprit, but also make sure you have an import statement at the top of your file for it as well. Edit here is the typical beginning of a java file, you need the R import where my comment is

package your.package.name;

import your.package.name.R;    // make sure you have this line
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
Sign up to request clarification or add additional context in comments.

8 Comments

xml files r not showing any error, although they do not have that import statement.
That statement needs to go at the top of the .java code files that you want to reference R, not the XML file
java file has package com.thenewbos.am; at the top\
It needs to be in the imports section, I will edit the answer
I added import com.thenewbos.am.R;. It was not there. But this also gives error the import cannot be resolved. Instead of R.java, I have BuildConfig.java file.
|
0

Verify the syntax on your XML files. The problem may not be in MainActivity.java. If there's an error on any of your XML files the class R won't be generated.

2 Comments

Look at the "Errors" view on Eclipse. Is there any errors? Sometimes Eclipse doesn't show the "red cross" on the class
Also, check your Manifest file to see if it's not referencing anything that doesn't exist on your project anymore, in case you excluded some artifact.
0

if you are using Eclipse, remove the R class import in your class and press CTRL + SHIFT + O, it will automatically import your classes. If it proposes your move than one R class, select the one from your project.

Comments

0

If you have an error in your XML file then R.java will not be generated. Try cleaning your project and look for any signs of errors on your XML files.

Comments

0

I had the same problem. The R.Java was not generated(in the gen folder). There was no error in the xml file. The issue was that I did not update the sdk completely. In the SDK manager we need to install the package whenever the "install package" button is enabled and close and open the sdk manager to check for updates. Close and reopen eclipse and check for updates in eclipse also.

Comments

0

See this question Eclipse giving error, missing R.java file after recent update, probably help you if you recently installed the ADT

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.