Android tutorial error: R cannot be resolved to a variable

前端 未结 12 581
野性不改
野性不改 2020-12-11 20:35

http://developer.android.com/training/basics/firstapp/building-ui.html

I have been following this tutorial, but I have two errors, both \"R cannot be resolved to a v

相关标签:
12条回答
  • 2020-12-11 20:58

    You have to make sure to

    1. Clean your project Project-->Clean
    2. The /res directory doesn't contain errors (some files will show up with a red icon on the file explorer)
    3. Your imports doesn't contain this line import android.R;
    4. Check that in AndroidManifest.xml, the attribute package has the correct value. <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="your.correct.package.name"
    0 讨论(0)
  • 2020-12-11 21:04

    I had the same issue while following the tutorial. Cleaning the project or cleaning the imports did not solve the problem.

    How the problem was (simply) solved : I quit Eclipse and relaunched it.

    0 讨论(0)
  • 2020-12-11 21:09

    2 possible things

    The package name specified in the Android Manifest isn't the same as the in the Java files.

    Or, your IDE hasn't generated the R.java file in the gen/ folder. Try building again (despite the error) and it will usually clear it up.

    Basically the R.java file is generated for you and in the same package so you can refer to it as simply R.

    0 讨论(0)
  • 2020-12-11 21:10

    This fixed it for me: https://stackoverflow.com/a/3259974/1538785

    Seems like eclipse likes to add an import line to java files for no reason. Go onto your java file, hit ctrl+shift+o and all the import statements will appear. Delete the line that says import andriod.R

    0 讨论(0)
  • 2020-12-11 21:14

    Pleas confirm there is no error in

    1- Project folder 2- Problem View of eclipse 3- Console 4- error log as in image enter image description here

    0 讨论(0)
  • 2020-12-11 21:14

    Right click on the Project, select "Android Tools" > "Add Support Library" > "Android Support Library, revision 11" > "Install"

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