ittianyu / BottomNavigationViewEx

An android lib for enhancing BottomNavigationView. 一个增强BottomNavigationView的安卓库。
MIT License
3.47k stars 558 forks source link

Error NullPointerExcption, 2.0.2, only in Google Play #134

Closed diridou closed 6 years ago

diridou commented 6 years ago

Hi, Here's the line where code crashes : BottomNavigationViewEx bnve = (BottomNavigationViewEx) findViewById(R.id.bnve);

Here's the error code :

java.lang.RuntimeException: at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3194) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3302) at android.app.ActivityThread.-wrap12 (Unknown Source) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1891) at android.os.Handler.dispatchMessage (Handler.java:108) at android.os.Looper.loop (Looper.java:166) at android.app.ActivityThread.main (ActivityThread.java:7425) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)`

Caused by:java.lang.NullPointerException: at com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.getBottomNavigationItemViews (BottomNavigationViewEx.java:463) at com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.b (BottomNavigationViewEx.java:252) at com.test.app.Activity.Main_activity.Main_activity_1.onCreate (Main_activity_1.java:71) at android.app.Activity.performCreate (Activity.java:7372) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1218) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3147)

It does'nt happen on Emulator or when a real device is connected to Android Studio. It only happen when app is released and downloaded on Google Play.

My graddle file :

`compileSdkVersion 28 buildToolsVersion '28.0.3' //27.0.3 defaultConfig { applicationId "com.test.app" minSdkVersion 19 targetSdkVersion 28 versionCode 14 versionName "2.1.6" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true multiDexEnabled true

`

Can you help me ? Thanks a lot

ittianyu commented 6 years ago

try to add proguard rules

-keep public class android.support.design.widget.BottomNavigationView { *; }
-keep public class android.support.design.internal.BottomNavigationMenuView { *; }
-keep public class android.support.design.internal.BottomNavigationPresenter { *; }
-keep public class android.support.design.internal.BottomNavigationItemView { *; }
diridou commented 6 years ago

It works thank you so much !!!

yalematta commented 5 years ago

I have added the proguard rules mentioned above, and there's still a crash here:

    public BottomNavigationItemView[] getBottomNavigationItemViews() {
        if (null != this.mButtons) {
            return this.mButtons;
        } else {
            BottomNavigationMenuView mMenuView = this.getBottomNavigationMenuView();
            this.mButtons = (BottomNavigationItemView[])this.getField(mMenuView.getClass(), mMenuView, "buttons");
            return this.mButtons;
        }
    }

getField is returning null after entering the catch NoSuchFieldException


    private <T> T getField(Class targetClass, Object instance, String fieldName) {
        try {
            Field field = targetClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(instance);
        } catch (NoSuchFieldException var5) {
            var5.printStackTrace();
        } catch (IllegalAccessException var6) {
            var6.printStackTrace();
        }

        return null;
    }

Any idea how to fix this?

ittianyu commented 5 years ago

Do you have add proguard rules ?

ittianyu commented 5 years ago

@yalematta