为什么android中出现R不存在错误?
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:196: package R does not exist
addPreferencesFromResource(R.xml.myfile);
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:344: package R does not exist
menu.add(0, MENU_SAVE, 0, R.string.menu_save)
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:346: package R does not exist
menu.add(0, MENU_CANCEL, 0, R.string.menu_cancel)
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:454: package R does not exist
errorMsg = mRes.getString(R.string.error_empty);
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:458: package R does not exist
errorMsg = mRes.getString(R.string.error_empty);
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:196: package R does not exist
addPreferencesFromResource(R.xml.myfile);
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:344: package R does not exist
menu.add(0, MENU_SAVE, 0, R.string.menu_save)
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:346: package R does not exist
menu.add(0, MENU_CANCEL, 0, R.string.menu_cancel)
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:454: package R does not exist
errorMsg = mRes.getString(R.string.error_empty);
^
packages/apps/Myfolder/src/com/android/myfolder/MyFile.java:458: package R does not exist
errorMsg = mRes.getString(R.string.error_empty);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
你可以尝试导入packagename.R;
You can try import packagename.R;
确保您有:
将“您的包名称”打包到调用 R 类的 java 文件中
Make sure you have:
package 'YOUR PACKAGE NAME' in java file that calls R class
就我而言,发生此错误是因为我更改了应用程序的包名称(当然是在发布到 Google Play 之前),但我忘记更新
manifest< 的
package
属性我的AndroidManifest.xml
文件中的 /code> 元素。一旦package
属性与新的包名称一致,错误就会消失。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 themanifest
element in myAndroidManifest.xml
file. Once thepackage
attribute agreed with the new package name, the error went away.检查您的资源文件中是否有任何错误或缺少任何依赖项。其中任何一个都会导致 R.java 类无法生成代码,从而出现很多像您所显示的错误。
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.
如果您从 ant 脚本构建,则必须运行 aapt。请参阅 $SDK_DIR/tools/ant/main_rules.xml 中的“-resource-src”目标。
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.
还要确保将当前的 Activity 包含在 AndroidManifest.xml 中的应用程序标记内。因此,如果 MyFile 是您的 Activity 子类,那么您应该在其中包含类似以下内容:
尽管其中实际内容取决于您的 Activity。有关此内容的更多信息,请访问:http://developer.android.com/guide /topics/manifest/manifest-intro.html
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:
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