Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
szgyuri opened this issue · comments
Hi!
I used your library 5 months ago and some users get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{hu.nextent.ni.cetli/hu.nextent.ni.cetli.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
I have no idea why it's happening. Please, if you can help me. Thanks, I'm sending the stacktrace:
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{hu.nextent.ni.cetli/hu.nextent.ni.cetli.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2572)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
at android.os.Parcel.readTypedList(Parcel.java:2008)
at com.yalantis.contextmenu.lib.MenuParams.(MenuParams.java:109)
at com.yalantis.contextmenu.lib.MenuParams.(MenuParams.java:11)
at com.yalantis.contextmenu.lib.MenuParams$1.createFromParcel(MenuParams.java:119)
at com.yalantis.contextmenu.lib.MenuParams$1.createFromParcel(MenuParams.java:117)
at android.os.Parcel.readParcelable(Parcel.java:2346)
at android.os.Parcel.readValue(Parcel.java:2243)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2592)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:786)
at com.yalantis.contextmenu.lib.ContextMenuDialogFragment.onCreate(ContextMenuDialogFragment.java:89)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2062)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1051)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:2138)
at android.support.v4.app.FragmentController.dispatchCreate(FragmentController.java:190)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:349)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
at hu.nextent.ni.cetli.MainActivity.onCreate(MainActivity.java:61)
at android.app.Activity.performCreate(Activity.java:6309)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Error says that you are trying to get list's size when its null in line 61
Just create a list or check for null before
In line 61 is super.onCreate(savedInstanceState) in my MainActivity. After this I got error in ContextDialogFragment (in line 89):
88. if (getArguments() != null) {
89. mMenuParams = getArguments().getParcelable(BUNDLE_MENU_PARAMS);
90. }
Therefore I wrote this issue, because this error isn't in my activity's code.