简体   繁体   English

版本2.2(级别8)上的Android支持库ActionBar NullPointerException-与preferences.xml冲突

[英]Android Support Library ActionBar NullPointerException on version 2.2 (level 8) - conflict with preferences.xml

I am using the v7 Support Library to show an ActionBar on Android 2.x. 我正在使用v7支持库在Android 2.x上显示ActionBar。

When I deploy the app to the device in my IDE (Intellij IDEA) the app works fine. 当我将应用程序部署到我的IDE(Intellij IDEA)中的设备时,该应用程序运行良好。

When I build and package the app to be deployed to the Play Store using maven, I find that I get the following exception when I install and run the packaged app on my device and the app crashes. 当我使用maven构建和打包要部署到Play商店的应用程序时,发现在设备上安装并运行打包的应用程序时出现以下异常,导致应用程序崩溃。 (It fails on the v8 simulator too). (它在v8模拟器上也失败)。 It works fine in both scenarios on android v4.3. 在android v4.3的两种情况下都可以正常工作。

Any idea why this would be crashing when built with maven? 知道为什么用Maven编译时会崩溃吗?

01-07 15:05:22.671      937-937/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.triopsis.as.mobile.android/com.triopsis.as.mobile.android.activity.MainMenuActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.internal.widget.ActionBarView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.internal.widget.ActionBarView
        at android.view.LayoutInflater.createView(LayoutInflater.java:513)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:677)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:614)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
        at android.app.Activity.setContentView(Activity.java:1647)
        at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:180)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:134)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
        at com.triopsis.as.mobile.android.activity.MainMenuActivity.onCreate(MainMenuActivity.java:43)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.reflect.InvocationTargetException
        at android.support.v7.internal.widget.ActionBarView.<init>(ActionBarView.java:218)
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
        at android.view.LayoutInflater.createView(LayoutInflater.java:500)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:677)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:614)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
        at android.app.Activity.setContentView(Activity.java:1647)
        at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:180)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:134)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
        at com.triopsis.as.mobile.android.activity.MainMenuActivity.onCreate(MainMenuActivity.java:43)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
        at android.support.v7.internal.widget.ActionBarView$HomeView.onFinishInflate(ActionBarView.java:1301)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.support.v7.internal.widget.ActionBarView.<init>(ActionBarView.java:218)
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
        at android.view.LayoutInflater.createView(LayoutInflater.java:500)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:677)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:614)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
        at android.app.Activity.setContentView(Activity.java:1647)
        at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:180)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:134)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
        at com.triopsis.as.mobile.android.activity.MainMenuActivity.onCreate(MainMenuActivity.java:43)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)

I have the following dependencies in maven: 我在Maven中具有以下依赖关系:

<dependencies>
    <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <version>4.0_r3</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>android.support</groupId>
        <artifactId>compatibility-v7-appcompat</artifactId>
        <version>19.0.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>android.support</groupId>
        <artifactId>compatibility-v7-appcompat</artifactId>
        <version>19.0.1</version>
        <type>apklib</type>
    </dependency>
    <dependency>
        <groupId>android.support</groupId>
        <artifactId>compatibility-v13</artifactId>
        <version>19.0.1</version>
        <type>jar</type>
    </dependency>
</dependencies>

and the following maven-android-plugin configured: 并配置了以下maven-android-plugin:

<build>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.8.2</version>
            <configuration>
                <sdk>
                    <platform>14</platform>
                </sdk>
            </configuration>
            <extensions>true</extensions>
        </plugin>
    </plugins>
</build>

UPDATE UPDATE

It has taken a while, but I have discovered that when I have the res/xml/preferences.xml file with PreferenceScreen settings then it causes this crash. 花费了一段时间,但是我发现当我使用带有PreferenceScreen设置的res / xml / preferences.xml文件时,会导致此崩溃。 If I remove this file, then it does not crash. 如果删除此文件,则不会崩溃。 Anyone know why that could cause this issue? 有人知道为什么会导致此问题吗?

Do you abslutely need features of android-maven-plugin version 3.8.2 ? 您绝对需要android-maven-plugin版本3.8.2吗? It seems to be bugy. 好像是马车。

A similar problem appeared in our project after updating android-maven-plugin from version 3.8.0 to 3.8.2 . android-maven-plugin3.8.03.8.2后,我们的项目中出现了类似的问题。

Falling back to version 3.8.0 solved the problem. 退回到版本3.8.0解决了该问题。

Symptoms: 症状:
Our conclusion is that the problem was in the linking of the apklib, all ressources (layouts, drawables...) referenced seemed to be disaligned. 我们的结论是,问题出在apklib的链接中,所有引用的资源(布局,可绘制对象...)似乎都没有对齐。 For example a layout or a drawable was displayed instead of another. 例如,显示的是布局或可绘制对象,而不是其他。 Application was crashing when accessing to a missing reference/id in a layout (the reference was not present because the wrong layout was loaded). 访问布局中缺少的引用/ ID时,应用程序崩溃(该引用不存在,因为加载了错误的布局)。

See issue http://code.google.com/p/maven-android-plugin/issues/detail?id=441 请参阅问题http://code.google.com/p/maven-android-plugin/issues/detail?id=441

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

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