6

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.

Psypher
  • 10,717
  • 12
  • 59
  • 83
  • 22.2.1 update has been released? – Eenvincible Jul 18 '15 at 19:52
  • @Eenvincible yes, yesterday: https://plus.google.com/+AndroidDevelopers/posts/XTtNCPviwpj – Mikhail Jul 18 '15 at 19:53
  • Yes..along with it new issues too. Last week I faced different problem when I updated to new library and now I have new problems. – Psypher Jul 18 '15 at 19:54
  • Last update had this problem https://stackoverflow.com/questions/31384935/getting-exception-java-lang-noclassdeffounderror-android-support-v7-app-appco/31432568#31432568 – Psypher Jul 18 '15 at 20:00
  • Set icon probably null holder navigation menu item view class line 113 – ceph3us Jul 18 '15 at 21:20
  • Didn't understand what you are trying to say.. – Psypher Jul 19 '15 at 04:50
  • Never roll back, fix the problem. Where is your code? – Jared Burrows Jul 19 '15 at 23:03
  • @JaredBurrows I had to because for the last update I got an exception and I wasted 2 days trying to fix the issue. This was the issue https://stackoverflow.com/questions/31384935/getting-exception-java-lang-noclassdeffounderror-android-support-v7-app-appco/31432568#31432568 – Psypher Jul 20 '15 at 12:49
  • That issue has nothing to do this issue. You simply added multidex. – Jared Burrows Jul 20 '15 at 14:30
  • Thats right. I was just saying the code was working before the update and later after the update it stopped working, just like the issue in this question. – Psypher Jul 20 '15 at 14:34

2 Answers2

8

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

Cheborra
  • 2,627
  • 4
  • 23
  • 39
0

I had the same issue and was able to avoid it with this code:

View header = LayoutInflater.from(this).inflate(R.layout.nav_header_main, null);
navigationView.addHeaderView(header);
TextView text = (TextView) header.findViewById(R.id.textView);
texto.setText("HELLO");
saravanan
  • 1,082
  • 1
  • 15
  • 30