为什么android中出现R不存在错误?

发布于 2024-10-09 06:16:08 字数 960 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

节枝 2024-10-16 06:16:09

你可以尝试导入packagename.R;

You can try import packagename.R;

乞讨 2024-10-16 06:16:08

确保您有:
将“您的包名称”打包到调用 R 类的 java 文件中

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

只是我以为 2024-10-16 06:16:08

就我而言,发生此错误是因为我更改了应用程序的包名称(当然是在发布到 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 the manifest element in my AndroidManifest.xml file. Once the package attribute agreed with the new package name, the error went away.

旧城烟雨 2024-10-16 06:16:08

检查您的资源文件中是否有任何错误或缺少任何依赖项。其中任何一个都会导致 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.

冰之心 2024-10-16 06:16:08
  1. 尝试清洁->构建(如果不只是重新启动 Eclipse,它就会起作用!)
  2. 如果您要导入项目,请确保选择正确的级别。
  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.
孤星 2024-10-16 06:16:08

如果您从 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.

寄与心 2024-10-16 06:16:08

还要确保将当前的 Activity 包含在 AndroidManifest.xml 中的应用程序标记内。因此,如果 MyFile 是您的 Activity 子类,那么您应该在其中包含类似以下内容:

<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>

尽管其中实际内容取决于您的 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:

<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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文