Skip to content
Advertisement

NullPointerException received when calling Bundle.getParcelable

I have a problem that I am trying to solve for few hours but cannot solve it and I need some help. I am trying to retrieve URL strings from a Login activity and trying to pass it to the Main activity using a parcelable object but I receive NullPointerException on getParcelable method.

Following is the code that creates the URL parcelable object and puts it to Intent and calls the Main activity

JavaScript

And the following is the URL parcelable class

JavaScript

Here is how I am receiving the parcelable object from the intent.

JavaScript

I am getting the following error on getParcelable line

JavaScript

Please help.

Thanks

Advertisement

Answer

Your problem is here:

JavaScript

urls is null at this point, and the readStringArray(String[]) method expects a parameter that is non-null, and the same length as the resulting read array. I find that method to be nearly useless as it doesn’t really work unless you know in advance a fixed size for the array. Alternatively, I suggest you use createStringArray():

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement