0

I copied my program at work to another computer so I can work on it here. When I try to create New project from existing code I get the dreaded R. cannot be resolved to a variable. Apparently, R.java is supposed to be in the gen folder but it isn't. Eclipse tells me to import R.java but we all know that isn't correct.

None of the many answers I have seen explain or solve my problem. Any help is greatly appreciated.

I've cleaned the project - as advised - many times after doing other things but it does nothing.

3
  • 1
    try doing something like this type R and give a control + space. It will give few suggestions among which you may have the R.java file related to your project. Import that R instead of the default android.R . Before doing all these check if your project shows any errors in the xml files. If you have any errors in any of your xml files the R.java file will not be created Commented Nov 21, 2012 at 2:43
  • @Sharath thanks. If you make this an answer I will accept. I'm kind of an idiot. I did have an error in my xml but I copied it from my work workspace that didn't have any errors so I don't know how that could be. I thought that it was somehow related to the error I was getting in my classes. Once I removed that file, which is something being tested anyway, I got it working. But thank you for giving some direction and not telling me to clean my project as I had said I had done. Kudos to you! Commented Nov 21, 2012 at 3:16
  • just posted it as an answer so that it would be helpful to one or the other.. Commented Nov 21, 2012 at 3:21

7 Answers 7

1

try doing something like this type R and give a control + space. It will give few suggestions among which you may have the R.java file related to your project. Import that R instead of the default android.R . Before doing all these check if your project shows any errors in the xml files. If you have any errors in any of your xml files the R.java file will not be created

Sign up to request clarification or add additional context in comments.

Comments

1

R. java gets generated .(Thats what gen stands for 'gen folder') Do not import R.java as suggested by Android, clean your project and rebuild it and the R.java file will be created in the gen folder unless your project has errors.

Let me know how it goes

1 Comment

Thanks for the response. But, as I said, I know that importing R.java is not the answer and I have tried to clean it. The only errors are the ones that come from R cannot be resolved to a variable. I understand that it is suppose to be generated but it isn't. I guess the question is 'Why isn't it being generating?'
1

Do not modify the source (such as importing R.java) if it worked on another computer.

Right click the project and select Android Tools -> Fix Project Properties.

If you do not have errors in your xml files, this should work.

EDIT:

If you do not mind other IDEs, I think IntelliJ IDEA is good for Android developing.(compared to Eclipse) and it should save a lot problems.

1 Comment

I guess I should have added all of this in my question but I also tried that (many times) and it did nothing for me. Also, I stated in my question and a comment that I know that the Eclipse answer of importing R.java isn't correct
0

Maybe you can also try doing this instead of creating 'New project from existing code':

In your eclipse go to: File -> Import -> General -> Existing Projects into Workspace -> browse to your project -> Finish

Hope that helps. :)

Comments

0

Try importing your R class manually. Go to a java file in one of your activities and try this in your import statements.

import com.yourpackage.name.R;

1 Comment

Is your R.java present in this package? If it is not then I think you have a problem with your layouts/xmls in your res folder. This happend to me once when I accidentally moved an xml file to another folder in the project workspace @codeMagic
0

Aside from the other solutions, try changing the build of your app through

properties > Android

then revert it back to your original build.

or just in case, try checking your layout or res folder

If I'm not mistaken, R couldn't be built if there is something wrong with the res folder.

Comments

0

Aside from the other solutions, try to delete the package that is causing the problem under the "gen" folder and let eclipse rebuild it.

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.