R cannot be resolved - Android, no import android.R; statement

前端 未结 10 1082
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 03:55

Ok, I am working on a new app and everything worked fine as long as I used a Relative View. However, I want a tabbed layout so I switched what I had (not much so far since

相关标签:
10条回答
  • 2020-12-11 04:37

    In my case it was caused since I refactored my project and moved some classes inside a folder structure. Those classes couldnt find the R as usual, since its based on the root source folder.

    0 讨论(0)
  • 2020-12-11 04:38

    Check that all of the strings you think you're using (e.g. "@string/Hello_world") actually exist in your strings.xml file. I got the OP's error after declaring a menu item using android:title="@string/Navigation", but I hadn't added <string name="Navigation">Navigation</string> to strings.xml

    0 讨论(0)
  • 2020-12-11 04:44
    1. You can try to "clean" your project.
    2. The default tech solution helps sometimes: restart Eclipse (seriously)
    3. If you have an error (something in your XML maybe, or something else), R cannot be compiled. If this is the case, try to find the first error noted. If you fix this, R will be compiled and found. If necesairy, use point 1. and 2. after fixing stuff.
    4. Remove all "import R" stuff in the import sections. You don't want that.
    0 讨论(0)
  • 2020-12-11 04:44

    Along with the great suggestions in the previous answers, make sure your Android target is set:

    1. Right-click on your project
    2. Choose Properties
    3. Choose Android in the left menu
    4. Tick a box next to the appropriate Project Build Target.
    5. Click Apply and OK

    Edit: A year later I found another cause. I had a .jpg image in my drawable folder with the same name as a .png image. Referencing this image in my code must have confused the program and it gave the "R cannot be resolved" error.

    0 讨论(0)
  • 2020-12-11 04:44

    I had the sample problem too and this worked for me.

    1.) Check for any errors in your Layout XML. Especially when it comes to text and titles

    You should use

        android:text="@string/hello" 
    

    instead of

        android:text="hello"  
    

    .2) Clean your project

    .3) Restart Eclipse

    0 讨论(0)
  • 2020-12-11 04:45

    If you're using Eclipse, trying giving it a kick by doing a Project/Clean and re-building your project. It sometimes has random trouble with the classpath on Android projects.

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