R cannot be resolved to a variable

后端 未结 29 1063
不知归路
不知归路 2020-11-28 14:14

I would like to fix this error

R cannot be resolved to a variable

I looked up many answers, but I could not get the right one;

相关标签:
29条回答
  • 2020-11-28 14:53

    I have just had this problem.

    It was caused because I had a redundant menu resource that referred to a non-existing string.

    Removed the menu XML and back came R.

    0 讨论(0)
  • 2020-11-28 14:53

    If you haven't yet, try cleaning your project as already suggested. In Eclipse Indigo, this is Project -> Clean... -> (Make sure your project(s) are checked) -> OK. After that, right click on your project and choose "Refresh".

    If this is still a issue, a few questions:

    1. Did you recently change the package name of your application in AndroidManifest.xml?
    2. Does the 'activity' node in your AndroidManifest.xml describing the class "Convert" specify a package/name that cannot be resolved naturally with that of your application? As an example, if your application is com.foo.bar and your activity is described as com.foobar.Convert, R.* will not automagically function -- you would need to explicitly include R for the proper package.
    0 讨论(0)
  • 2020-11-28 14:55

    Check your AndroidManifest.xml file, see if the package name is correct. If you copied an example it is likely this is wrong and the source of your problem.

    0 讨论(0)
  • 2020-11-28 14:55

    Check if the package name in the AndroidManifest.xml file is the same than the package name of your java class.

    Eg. AndroidManifest.xml

     package="com.example.de.vogella.android.widget.example"
    

    In your class MyWidgetProvider.java

    package com.example.de.vogella.android.widget.example;
    

    It was the cause of my error in this example.

    0 讨论(0)
  • 2020-11-28 14:57

    If Clean/Rebuild Project doesn't work try to check our package name in AndroidManifest.xml.

    The problem "R cannot be resolved" happens when you change your package name in the AndroidManifest.xml file. It uses your Android package name to create a subdirectory under the "gen" directory where it stores the R.java file.

    0 讨论(0)
  • 2020-11-28 14:58

    I just had this error on my first hello world android application (3-Nov-2013).

    Along with a few pointers from other users, this is what I had to do:

    Control+Shift+O

    Delete the import *.R from the top of the main activity .java file

    Save the file, clean and compile the project (usually build is automatic)

    Run SDK Manager, enable the build tools if not already checked, and hit Update regardless

    Close and reopen Eclipse and the problem was gone

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