Java – attempt to read NullPointerException of parcel string []
•
Java
When I create an object from parcel, when I try to read back a string [], I get a NullPointerException This 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 the property of my class. It is a string [], but I get NullPointerException I checked dev's documentation, but there was nothing there I followed this tutorial, where they used readstringarray
Any suggestions? thank you
Solution
When calling readstringarray, you are providing an empty array for parcel For it to work, you must initialize indoormaps You may want to create stringarray
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码