NullPointerException tries to read Parcel String []

I get a NullPointerException when I try to read String[] when I create an object from Parcel . Here is my code:

 @Override public void writeToParcel(Parcel out, int flags) { out.writeInt(floors); out.writeStringArray(indoorMaps); } public static final Parcelable.Creator<Building> CREATOR = new Parcelable.Creator<Building>() { public Building createFromParcel(Parcel in) { return new Building(in); } public Building[] newArray(int size) { return new Building[size]; } }; private Building(Parcel in) { floors = in.readInt(); in.readStringArray(indoorMaps); } 

So, innerMaps is an attribute of my class, and this String[] , but I get an exception NullPointerException. I checked the dev documentation, but there is nothing there. I followed this tutorial and they use readStringArray .

Any suggestions? Thanks

+6
source share
1 answer

You pass an array of Parcel a null when you call readStringArray . For it to work, you need to initialize indoorMaps . You probably want to createStringArray .

+12
source

Source: https://habr.com/ru/post/916763/


All Articles