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 Parcel
a null
array when calling readStringArray
. For it to work, you would have to initialize indoorMaps
. You probably want createStringArray
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With