Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Nullpointer exception after updating to Android design support 22.2.1

My project was working fine just before I updated to Android design support 22.2.1, after I update and run the program I get the below error. The exception does not tell which line in code or the java file is causing the error so don't know what code to post.It seems some internal error of android design support.

My activity is extending AppCompatActivity and my test device API 15(Android 4.04).

I am using NavigationView and DrawerLayout in my code.

My build.gradle

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.stackoverflow.ranjith.androidprojdel"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.+'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.android.support:cardview-v7:22.2.+'
compile 'com.android.support:recyclerview-v7:22.2.+'
compile 'com.google.android.gms:play-services-plus:7.5.0'
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile 'com.android.support:design:22.2.+'
compile 'joda-time:joda-time:2.8.1'
}

Exception:

07-19 00:52:49.338: E/AndroidRuntime(15556): FATAL EXCEPTION: main
07-19 00:52:49.338: E/AndroidRuntime(15556): java.lang.NullPointerException
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.support.design.internal.NavigationMenuItemView.setIcon(NavigationMenuItemView.java:113)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.support.design.internal.NavigationMenuItemView.initialize(NavigationMenuItemView.java:72)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.getView(NavigationMenuPresenter.java:305)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.AbsListView.obtainView(AbsListView.java:2045)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.ListView.makeAndAddView(ListView.java:1772)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.ListView.fillDown(ListView.java:672)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.ListView.fillFromTop(ListView.java:732)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.ListView.layoutChildren(ListView.java:1625)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.AbsListView.onLayout(AbsListView.java:1875)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:931)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1653)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1511)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1416)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1653)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1511)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1416)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.View.layout(View.java:11390)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewGroup.layout(ViewGroup.java:4332)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1490)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2455)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.os.Looper.loop(Looper.java:137)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at android.app.ActivityThread.main(ActivityThread.java:4424)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at java.lang.reflect.Method.invokeNative(Native Method)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at java.lang.reflect.Method.invoke(Method.java:511)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
07-19 00:52:49.338: E/AndroidRuntime(15556):    at dalvik.system.NativeStart.main(Native Method)

Update

When I rollback to 22.2.0 the error disappears, not sure what is the problem.

like image 783
Psypher Avatar asked Jul 18 '15 19:07

Psypher


1 Answers

The problem is related to the NavigationView menu xml.

Mine looks like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
            android:id="@+id/navigation_subheader"
            android:title="Titulo">
        <menu>
            <item
                    android:id="@+id/navigation_sub_item_1"
                    android:icon="@drawable/abc_btn_radio_material"
                    android:title="sub-1"/>
            <item
                    android:id="@+id/navigation_sub_item_2"
                    android:icon="@drawable/abc_btn_rating_star_on_mtrl_alpha"
                    android:title="sub-2"/>
        </menu>
    </item>
</menu>

but if I switch to a project drawable icon, its fixed:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
            android:id="@+id/navigation_subheader"
            android:title="Titulo">
        <menu>
            <item
                    android:id="@+id/navigation_sub_item_1"
              ----> android:icon="@drawable/some_local_drawable"
                    android:title="sub-1"/>
            <item
                    android:id="@+id/navigation_sub_item_2"
              ----> android:icon="@drawable/some_local_drawable"
                    android:title="sub-2"/>
        </menu>
    </item>
</menu>

Of course, this happens after updating to 22.2.1

like image 175
Cheborra Avatar answered Oct 20 '22 04:10

Cheborra