java - setContentView 上的另一个 Resources$NotFoundException

标签 java android xml resources

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

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

    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 文件夹并清理了项目,但没有任何改进。我还重新启动了我的 PC 并明确关闭了该项目。 graphics.xml 文件没有明显的错误——它与我所有其他 XML 文件存在于同一个文件夹中;它没有写保护或隐藏。 Eclipse 不会为它标记任何错误或警告。

提前致谢。

最佳答案

我在 android-developers Google groups 上得到了这个问题的答案,我也在那里发布了这个问题。这位有洞察力的程序员是“Bob Smith”,只是为了给予应有的荣誉。

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

关于java - setContentView 上的另一个 Resources$NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16652437/

相关文章:

没有xml的Android jetpack撰写 fragment

php - 我的 Android 无法连接到我的网络服务器

android - 离线隔离环境中的Android Studio

xml - 对 XML 文件进行排序

java - 使用流 : Java 8 按多个属性进行分组和排序

java - 我如何在 IntelliJ 中显示通知?

java - 根元素类型 "plist"的文档类型声明必须以 '>' 结尾

xml - 仅返回XQuery FLWOR序列中的一个元素

java - 如何设置约束来限制单个节点上特定类型的关系数量

java - 非军事时间中的 JFreeChart TimeSeries 轴