java: R cannot be resolved to a variable

后端 未结 6 2010
北恋
北恋 2021-01-27 06:03

I know this question has been asked before but I am at my witts end with this. I have just created a new project and getting this error.

Ofcourse the R.java file is not

相关标签:
6条回答
  • 2021-01-27 06:13

    Had this happen a while back, my sdk/build-tools folder was missing a build target for some reason. Check in there to see if you have any folders.

    0 讨论(0)
  • make sure there is no error in resource file, then as soon as you build your project you will get R.java generated, point to note here is no matter whether your java code does not compile, R.java will generate if there is no problem with resource file.

    If this step succeed you can import all necessary R.java file. Note that there may be multiple R.java file if you have included library project in your project. All R.java files will be in respective packages. for eg. I have "com.actionsherlock.R.java" & "com.myproject.R.java"

    in this case above case 1st import is must com.actionsherlock.R. However, I you no library project included, you need not import R.java as this file would be generate in the same package.

    0 讨论(0)
  • 2021-01-27 06:16

    In my case I am using java 1.6 and it is not supporting android 5.0 so removed those library files in android sdk, then clean the project it is working fine.

    0 讨论(0)
  • 2021-01-27 06:17

    If you have any errors in your resource files, the tools will not generate an R.java file. Look for and fix all errors in the .xml files before worrying about class com.example.myfirstapp.R not being defined. If you have no errors in the .xml files, then clean and rebuild your project.

    Also, just to rule out a programming environment problem if you're using Eclipse, right-click on the project name in the Package Explorer, navigate to Android Tools and select "Fix Project Properties".

    0 讨论(0)
  • 2021-01-27 06:17

    Follow simple following steps

    • Open Android SDK Manager
    • Install Android SDK build-tool (In Tools)
    • Restart Eclipse
    0 讨论(0)
  • 2021-01-27 06:36

    This just worked for me.

    Added a character to the manifest and saved. Deleted said character cleaned projected and package created under gen with buildconfig and R java in it.

    Why is worked I have no idea.

    0 讨论(0)
提交回复
热议问题