简体   繁体   English

setContentView上的另一个资源$ NotFoundException

[英]Another Resources$NotFoundException on setContentView

There are lots of Resources$NotFoundException questions on Stack Overflow and I've reviewed them and tried the various suggestions to no avail. Stack Overflow上有很多资源$ NotFoundException问题,我已经审阅了它们,并尝试了各种建议无济于事。

I had a perfectly working layout to display some graphics with some buttons underneath and I modified some of the buttons and started to get this error. 我有一个完美的工作布局,显示一些图形与下面的一些按钮,我修改了一些按钮,并开始得到这个错误。 I couldn't see anything wrong with my changes but just to narrow it down I deleted ALL the buttons, so now I just have a LinearLayout with an ImageView and I'm still getting the error. 我没有看到我的更改有什么问题,但只是为了缩小它我删除了所有按钮,所以现在我只有一个带有ImageView的LinearLayout,我仍然得到错误。 My Java: 我的Java:

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

My XML: 我的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>

The error says android.content.res.Resources$NotFoundException: Resource ID #0x7f030005 . 错误说android.content.res.Resources $ NotFoundException:资源ID#0x7f030005 In the R.java file that resource is identified with the graphics . 在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;

I deleted the gen folder and did a clean the project with no improvement. 我删除了gen文件夹并做了一个干净的项目没有任何改进。 I also rebooted my PC and did an explicit close of the project. 我还重新启动了我的电脑并明确关闭了该项目。 There's nothing obviously wrong with the graphics.xml file - it exists in the same folder with all my other XML files; graphics.xml文件没有明显的错误 - 它存在于与我所有其他XML文件相同的文件夹中; it's not write-protected or hidden. 它没有写保护或隐藏。 Eclipse doesn't flag any errors or warnings for it. Eclipse不会标记任何错误或警告。

Thanks in advance. 提前致谢。

I got the answer to this on the android-developers Google groups, where I also posted this question. 我在Android开发者谷歌小组得到了答案,我也发布了这个问题。 The insightful programmer was "Bob Smith", just to give credit credit where it's due. 这位富有洞察力的程序员是“Bob Smith”,只是为了给予应有的信用额度。

My bug was that the resource it was seeking was not in the correct res folder. 我的错误是它正在寻找的资源不在正确的res文件夹中。 My app runs in landscape mode on a tablet. 我的应用在平板电脑上以横向模式运行。 In the manifest everything is constrained to run that way (in fact in the code it's constrained to run on one particular tablet that the company ships with their product). 在清单中,一切都被限制为以这种方式运行(实际上在代码中,它被限制为在公司随产品提供的一个特定平板电脑上运行)。 All the resource and layout files live in layout-land. 所有资源和布局文件都存在于layout-land中。 Bob didn't know any of this but he asked the key question: were my resource files really in the right res folder? 鲍勃不知道这些,但他问了一个关键问题:我的资源文件真的在正确的res文件夹中吗?

你可以这样做:Project> Clean and REFRESH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM