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 不会为它标记任何错误或警告。
提前致谢。