Android Parcelable readStringArray bad array lengths [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-06 15:53:28

This is the implementation of readStringArray():

public final void readStringArray(String[] val) {
    int N = readInt();
    if (N == val.length) {
        for (int i=0; i<N; i++) {
            val[i] = readString();
        }
    } else {
        throw new RuntimeException("bad array lengths");
    }
}

So it seems as though the length of your models.names array is the reason it's throwing that error. You need to know the exact size of your array beforehand to create the array so that it doesn't throw the error.

I think createStringArray() suffices, you don't need to call source.readStringArray(models.names); so just delete that and it should work.


I think there may be a language barrier here, so i'll mention the exact code you should have:

@Override
    public SingleModels createFromParcel(Parcel source) {
        SingleModels models = new SingleModels();
        models.name = source.readString();
        models.names = source.createStringArray();
        return models;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!