Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when using in NavigationView #15

Closed
naman14 opened this issue Aug 25, 2015 · 4 comments
Closed

NPE when using in NavigationView #15

naman14 opened this issue Aug 25, 2015 · 4 comments

Comments

@naman14
Copy link

naman14 commented Aug 25, 2015

MaterialDrawableBuilder drawable = MaterialDrawableBuilder.with(this).setColor(Color.WHITE).setIcon(MaterialDrawableBuilder.IconValue.LIBRARY_MUSIC).build();
 navigationView.getMenu().findItem(R.id.nav_library).setIcon(drawable);

Doing this results in NullPointerException in NavgationMenuItemView

java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable()' on a null object reference
            at android.support.design.internal.NavigationMenuItemView.setIcon(NavigationMenuItemView.java:114)
            at android.support.design.internal.NavigationMenuItemView.setIconTintList(NavigationMenuItemView.java:144)
            at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.getView(NavigationMenuPresenter.java:325)

This only happens with design support lib 22.2.0.+. Worked fine till 22.2.0. Also broken on v23.

@code-mc
Copy link
Owner

code-mc commented Aug 25, 2015

The MaterialDrawableBuilder drawable should be Drawable drawable but that probably isn't the reason it's doing that I guess if it worked before. What exactly is this referring to, an activity?

@naman14
Copy link
Author

naman14 commented Aug 25, 2015

My bad ,it should be Drawable but yeah that's a typo here.
this is a Activity. BTW this issue is also reported here-https://code.google.com/p/android/issues/detail?id=180481
And here-
http://stackoverflow.com/questions/31494946/getting-nullpointer-exception-after-updating-to-android-design-support-22-2-1

From what i understand, Drawable.ConstantState always returns null in default behavior. Probably have to override getConstantState() in MaterialDrawable

@code-mc
Copy link
Owner

code-mc commented Aug 25, 2015

This one is hard for me to justify fixing as the default framework behavior is what it currently does. If the support lib uses one of the methods wrong than the report over there is probably the only thing that will fix it in the long run.

A temporary fix would be overriding the MaterialDrawable class and implementing the getConstantState() method there yourself. Cast the Drawable to that overridden one and it should work if I understood everything correctly.

@code-mc
Copy link
Owner

code-mc commented Aug 25, 2015

I have starred the issue btw, I hope it gets fixed asap :)

@code-mc code-mc closed this as completed Sep 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants