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

我的未来我决定 提交于 2019-12-11 04:06:55

问题


I am using the v7 Support Library to show an ActionBar on Android 2.x.

When I deploy the app to the device in my IDE (Intellij IDEA) the app works fine.

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. (It fails on the v8 simulator too). It works fine in both scenarios on android v4.3.

Any idea why this would be crashing when built with 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:

<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:

<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

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. If I remove this file, then it does not crash. Anyone know why that could cause this issue?


回答1:


Do you abslutely need features of android-maven-plugin version 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.

Falling back to version 3.8.0 solved the problem.

Symptoms:
Our conclusion is that the problem was in the linking of the apklib, all ressources (layouts, drawables...) referenced seemed to be disaligned. 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).

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



来源:https://stackoverflow.com/questions/20975969/android-support-library-actionbar-nullpointerexception-on-version-2-2-level-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!