why does R does not exist error come in android?

穿精又带淫゛_ 提交于 2019-11-29 03:39:05

Check if there are any errors in your resource files or any missing dependencies. Either of these will cause the R.java class to not be code-generated and thus a lot of errors like the ones you have shown.

In my case, this error occurred because I had changed the package name of the app (before publishing to Google Play, of course), but I forgot to update the package attribute of the manifest element in my AndroidManifest.xml file. Once the package attribute agreed with the new package name, the error went away.

Make sure you have: package 'YOUR PACKAGE NAME' in java file that calls R class

  1. Try Clean-> Build (If not just restart eclipse, it just worked!)
  2. In case you are importing project, make sure you choose proper Level.

If you are building from an ant script, you must run aapt. See the "-resource-src" target in $SDK_DIR/tools/ant/main_rules.xml.

Also make sure to include your current Activity in the AndroidManifest.xml, inside the application tags. So if MyFile is your Activity subclass, you should have something like this in it:

<application 
    android:label="@string/app_name" 
    ... >

        <activity android:name=".MyFile"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name">
            <intent-filter> 
                <action android:name="android.intent.action.VIEW" /> 
            </intent-filter> 
        </activity>
        ..


</application>

Although what's actually in there depends on your activity. More information about this at: http://developer.android.com/guide/topics/manifest/manifest-intro.html

You can try import packagename.R;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!