从库项目中膨胀活动时的Android资源$ NotFoundException

时间:2016-04-19 16:47:37

标签: android android-studio mupdf

当我将MuPDF库添加到项目中时,可能会导致此问题。

这是错误日志:

FATAL EXCEPTION: main
        Process: ch.my.app, PID: 18899
        java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.my.app/com.artifex.mupdflib.MuPDFActivity}: android.content.res.Resources$NotFoundException: File  from drawable resource ID #0x7f0d000f: .xml extension required
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
            at android.app.ActivityThread.access$1000(ActivityThread.java:198)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6837)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
         Caused by: android.content.res.Resources$NotFoundException: File  from drawable resource ID #0x7f0d000f: .xml extension required
            at android.content.res.Resources.twLoadColorStateList(Resources.java:4013)
            at android.content.res.Resources.loadColorStateList(Resources.java:3943)
            at android.content.res.Resources.getColor(Resources.java:2072)
            at com.artifex.mupdflib.MuPDFActivity.onCreate(MuPDFActivity.java:295)
            at android.app.Activity.performCreate(Activity.java:6500)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218) 
            at android.app.ActivityThread.access$1000(ActivityThread.java:198) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:145) 
            at android.app.ActivityThread.main(ActivityThread.java:6837) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:372) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 

我正在添加MuPDF库作为模块,这是settings.gradle

include ':app'
include ':library_MuPDF'

模块应用的build.gradle包含:

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 23
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
    compile 'com.android.support:support-v4:22.2.1'
}

项目涉及:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Android工作室没有出现任何问题。 这是它崩溃的代码:

getWindow().setStatusBarColor(getResources().getColor(R.color.actionbar_background_dark));

当我禁用此功能时,问题出在膨胀时:

mButtonsView = getLayoutInflater().inflate(R.layout.buttons, null);

这是膨胀错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ch.app.app, PID: 3283
    java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.app.app/com.artifex.mupdflib.MuPDFActivity}: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2484)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
        at android.app.ActivityThread.access$900(ActivityThread.java:150)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:168)
        at android.app.ActivityThread.main(ActivityThread.java:5845)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
     Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class <unknown>
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at com.artifex.mupdflib.MuPDFActivity.makeButtonsView(MuPDFActivity.java:1091)
        at com.artifex.mupdflib.MuPDFActivity.createUI(MuPDFActivity.java:587)
        at com.artifex.mupdflib.MuPDFActivity.onCreate(MuPDFActivity.java:473)
        at android.app.Activity.performCreate(Activity.java:6248)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544) 
        at android.app.ActivityThread.access$900(ActivityThread.java:150) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:168) 
        at android.app.ActivityThread.main(ActivityThread.java:5845) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 

我检查的所有内容看起来都正确,我清理了项目,干净安装了应用程序,删除了使用此库的所有其他应用程序,这个问题仍在发生。

我在哪里可以寻找其他可能的问题?

由于

1 个答案:

答案 0 :(得分:0)

确保您的库项目在res / values文件夹中有color.xml文件