3

Stack Overflow 上有很多 Resources$NotFoundException 问题,我已经查看了它们并尝试了各种建议,但均无济于事。

我有一个完美的工作布局来显示一些带有一些按钮的图形,我修改了一些按钮并开始出现这个错误。我看不出我的更改有什么问题,但只是为了缩小范围,我删除了所有按钮,所以现在我只有一个带有 ImageView 的 LinearLayout,但我仍然遇到错误。我的爪哇:

    try  {
        setContentView(R.layout.graphics);
    }
    catch (Exception e)  {
        Log.d("DGraphActivity", "setContentView crash");   
    }

我的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
   <ImageView 
      android:id="@+id/image2"
      android:layout_width="0px"
      android:layout_weight="2"
      android:layout_height="match_parent"
      android:scaleType="fitCenter">
    </ImageView>
 </LinearLayout>

错误显示android.content.res.Resources$NotFoundException: Resource ID #0x7f030005。在 R.java 文件中,该资源用图形标识。. .

public static final class layout {
        public static final int addcomment=0x7f030000;
        public static final int areyousure=0x7f030001;
        public static final int downarrow=0x7f030002;
        public static final int downleftarrow=0x7f030003;
        public static final int downrightarrow=0x7f030004;
        public static final int graphics=0x7f030005;
        public static final int infofromoperator=0x7f030006;

我删除了 gen 文件夹并清理了项目,但没有任何改进。我还重新启动了我的电脑并明确关闭了项目。graphics.xml 文件并没有明显的问题——它与我的所有其他 XML 文件位于同一个文件夹中;它没有写保护或隐藏。Eclipse 不会为它标记任何错误或警告。

提前致谢。

4

2 回答 2

12

我在 android-developers Google groups 上得到了答案,我也在其中发布了这个问题。有见地的程序员是“鲍勃史密斯”,只是为了在应得的地方给予信用。

我的错误是它正在寻找的资源不在正确的 res 文件夹中。我的应用程序在平板电脑上以横向模式运行。在清单中,一切都被限制为以这种方式运行(事实上,在代码中,它被限制为在公司随其产品提供的特定平板电脑上运行)。所有的资源和布局文件都存在于 layout-land 中。Bob 对此一无所知,但他提出了一个关键问题:我的资源文件真的在正确的 res 文件夹中吗?

于 2013-05-21T18:36:44.947 回答
-3

你可以这样做:项目>清理和刷新

于 2013-05-20T15:26:18.313 回答