【问题标题】:Resources$NotFoundException in built-in Android resource?内置Android资源中的Resources$NotFoundException?
【发布时间】:2012-03-21 17:32:03
【问题描述】:

我在eclipse上启动了一个Android项目,做了一个简单的加载栏,如下:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LOG = true;

    // Initialize a GUI
    if(LOG) Log.d(TAG, "starting  content view and progress bar notifications");

    //initialize resource 
    // i put try to check the Exception
    try {
        setContentView(R.layout.load);
        RelativeLayout rl = (RelativeLayout) findViewById(R.id.loading_layout);
        mProgress = (ProgressBar) rl.findViewById(R.id.progressBarLoad);
        mProgressText = (TextView) rl.findViewById(R.id.textProgressLoad);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if(LOG) Log.d(TAG, "bar notifications initialized");
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                if(LOG){
                    Log.d(TAG, "starting update "+mProgress.toString());
                    Log.d(TAG, "starting update "+mProgressText.toString());
                }

                while (mProgressStatus<100) {
                    //Do all process here
                    /*
                    if(mProgress % getNumberSubProcess() == 0){

                    }
                    */
                    LoadFEIAppActivity.this.update();
                    mProgressStatus += 0.01d; 
                }

                if(mProgressStatus==100){
                    LoadFEIAppActivity.this.update();
                    if(LOG) Log.d(TAG, "DONE");
                    return;
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    });

    t.start();

    /*
    if(mProgressStatus==100){
        Intent intent = new Intent(this, RegisterEmail.class);
        startActivity(intent);
    } 
     */     
}

但应用程序没有按预期运行并且我收到许多异常:

**03-21 16:25:51.977: W/System.err(363): android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
03-21 16:25:51.987: W/System.err(363):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
03-21 16:25:51.997: W/System.err(363):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-21 16:25:51.997: W/System.err(363):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
03-21 16:25:51.997: W/System.err(363):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
03-21 16:25:52.007: W/System.err(363):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
03-21 16:25:52.017: W/System.err(363):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-21 16:25:52.017: W/System.err(363):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-21 16:25:52.017: W/System.err(363):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
03-21 16:25:52.028: W/System.err(363):  at android.app.Activity.setContentView(Activity.java:1622)
03-21 16:25:52.028: W/System.err(363):  at unicamp.ia.feia.LoadFEIAppActivity.onCreate(LoadFEIAppActivity.java:45)
03-21 16:25:52.037: W/System.err(363):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-21 16:25:52.047: W/System.err(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-21 16:25:52.047: W/System.err(363):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-21 16:25:52.057: W/System.err(363):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-21 16:25:52.067: W/System.err(363):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-21 16:25:52.077: W/System.err(363):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 16:25:52.087: W/System.err(363):  at android.os.Looper.loop(Looper.java:123)
03-21 16:25:52.087: W/System.err(363):  at android.app.ActivityThread.main(ActivityThread.java:4363)
03-21 16:25:52.097: W/System.err(363):  at java.lang.reflect.Method.invokeNative(Native Method)
03-21 16:25:52.118: W/System.err(363):  at java.lang.reflect.Method.invoke(Method.java:521)
03-21 16:25:52.127: W/System.err(363):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-21 16:25:52.127: W/System.err(363):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-21 16:25:52.137: W/System.err(363):  at dalvik.system.NativeStart.main(Native Method)
03-21 16:25:52.137: W/System.err(363): Caused by: java.lang.reflect.InvocationTargetException
03-21 16:25:52.177: W/System.err(363):  at android.widget.TextView.<init>(TextView.java:320)
03-21 16:25:52.177: W/System.err(363):  at java.lang.reflect.Constructor.constructNative(Native Method)
03-21 16:25:52.189: W/System.err(363):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
03-21 16:25:52.197: W/System.err(363):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
03-21 16:25:52.207: W/System.err(363):  ... 22 more
03-21 16:25:52.207: W/System.err(363): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/progress_indeterminate_horizontal.xml from color state list resource ID #0x1030008
03-21 16:25:52.237: W/System.err(363):  at android.content.res.Resources.loadColorStateList(Resources.java:1813)
03-21 16:25:52.247: W/System.err(363):  at android.content.res.TypedArray.getColorStateList(TypedArray.java:289)
03-21 16:25:52.258: W/System.err(363):  at android.widget.TextView.<init>(TextView.java:627)
03-21 16:25:52.267: W/System.err(363):  ... 26 more
03-21 16:25:52.277: W/System.err(363): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/progress_indeterminate_horizontal.xml from xml type colorstatelist resource ID #0x1030008
03-21 16:25:52.297: W/System.err(363):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1912)
03-21 16:25:52.307: W/System.err(363):  at android.content.res.Resources.loadColorStateList(Resources.java:1808)
03-21 16:25:52.317: W/System.err(363):  ... 28 more
03-21 16:25:52.317: W/System.err(363): Caused by: java.io.FileNotFoundException: res/drawable/progress_indeterminate_horizontal.xml
03-21 16:25:52.357: W/System.err(363):  at android.content.res.AssetManager.openXmlAssetNative(Native Method)
03-21 16:25:52.367: W/System.err(363):  at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:469)
03-21 16:25:52.377: W/System.err(363):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1894)
03-21 16:25:52.377: W/System.err(363):  ... 29 more**

在stackoverflow上的研究,我发现了一些类似的问题,但没有一个完整的解决方案:

  • 清理和重建项目(无效)
  • 检查所有资源(都在 res/ 中),即 values/strings/layout/
  • 我检查 xdpi 文件夹,它们的密度不同(每张照片我都有一个版本):见Resources NotFoundException?

我认为有两个问题:

  • 照片的密度会影响编译过程吗?
  • 或者 Eclipse 缺少必要的内置资源?我正在考虑它,因为这条消息 Caused by: android.content.res.Resources$NotFoundException: File res/drawable/progress_indeterminate_horizontal.xml

感谢您的帮助!

【问题讨论】:

  • 嗨 gcrav 发布您的 progress_indeterminate_horizo​​ntal.xml 文件...
  • 问题是:我没有创建这个文件:P
  • 标题中无需加上“已解决”。你已经接受了一个答案,这就够了。

标签: android exception layout resources


【解决方案1】:

首先检查你有res/drawable/progress_indeterminate_horizontal.xml 吗?那么

progress_indeterminate_horizontal.xml 在这个 xml 中你没有你的 progressbar 的一些状态所以它的问题,

查看此链接 http://quickandroidblog.blogspot.in/2011/08/change-android-horizontal-progress-bar.html

【讨论】:

  • 嗨 Jorgesys 和 Samir,问题在于我没有创建 res/drawable/progress_iderteminate_horizontal.xml。我认为这是Android SDK的内置资源(?)
  • 这个问题以前没有出现过,只有在我创建另一个活动时才出现。我将发布有问题的布局和清单中的文件
  • 对不起,samir,我误会了你的意思(这个中级英语......:P),我会尝试再次发布
  • 好的@Samir,阅读所有帖子,并“破解”android,我做了这个:在文件res/layout/loading.xml中,这是有问题的文件,我添加了一个简单的行:android:progressDrawable="@android:drawable/progress_indeterminate_horizontal"/&gt;并且特定的异常(InflateException)消失了。我现在有其他例外:E/AndroidRuntime(295): java.lang.RuntimeException: Unable to instantiate application unicamp.ia.feia.fEIApp2012: java.lang.ClassNotFoundException: unicamp.ia.feia.fEIApp2012 in loader dalvik.system.PathClassLoader@44e8cdd0
  • ops,我在元素 中添加该行;)
【解决方案2】:

.xml 文件

res/drawable/progress_indeterminate_horizo​​ntal.xml

引用了您的项目中不存在的颜色!

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/progress_indeterminate_horizontal.xml from color state list resource ID #0x1030008

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/progress_indeterminate_horizontal.xml from xml type colorstatelist resource ID #0x1030008

是的,照片的密度会影响,但由于您使用的是默认文件夹 res/drawable/,并且您的项目中有资源,因此不会影响编译

发布你的 res/drawable/progress_indeterminate_horizo​​ntal.xml

【讨论】:

    【解决方案3】:

    如下,manifest.xml和有问题的Activity中使用的布局:

    我的项目中的层次结构树是(与 xml 文件相关):

    • 分辨率/
      • 布局/
        • 加载.xml
        • registeremail.xml
      • 可绘制/
        • hdpi/
          • logo.png
          • mulherfeia2012.jpg
        • mdpi/
          • 什么都没有
        • ldpi/
          • 什么都没有

    res/layout/loading.xml,我试着跑了

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/loading_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <ProgressBar
            android:id="@+id/progressBarLoad"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true" />
    
        <TextView
            android:id="@+id/textProgressLoad"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/progressBarLoad"
            android:layout_centerHorizontal="true"
            android:text="@string/loading_message"
            android:textColor="@android:color/white" />
        <ImageView
            android:id="@+id/imageLoad"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/progressBarLoad"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:contentDescription="@string/logo_feia_description"
            android:src="@drawable/mulherfeia2012" />
    </RelativeLayout>
    

    还有AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="unicamp.ia.feia"
        android:versionCode="1"
        android:versionName="0.1" >
    
    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" android:maxSdkVersion="7"/>
    
    <application
        android:icon="@drawable/feia12_logo_low"
        android:label="@string/app_name" 
        android:testOnly="false" 
        android:debuggable="true">
        <activity
            android:name=".LoadFEIAppActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <activity 
            android:name=".RegisterEmail">
        </activity>
    </application>
    </manifest>
    

    非常感谢您的帮助!

    【讨论】:

    • 记住:我没有在任何时候创建文件res/drawable/progress_indeterminate_horizontal.xml
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多