I am getting a NullPointerException when I am trying to read back a 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 indoorMaps is an attribute of my class, and it a String[], but I get the NullPointerException. I have checked the dev’s documentation but there’s nothing there.
I followed this tutorial and they are using readStringArray in there.
Any suggestions? Thanks
You are giving
Parcelanullarray when callingreadStringArray. For it to work, you would have to initializeindoorMaps. You probably wantcreateStringArrayinstead.