Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有相同类的可包裹嵌套writeTypedList_Java_Android_Adapter_Android Recyclerview - Fatal编程技术网

Java 具有相同类的可包裹嵌套writeTypedList

Java 具有相同类的可包裹嵌套writeTypedList,java,android,adapter,android-recyclerview,Java,Android,Adapter,Android Recyclerview,让我知道我在做什么。我有一个主要活动,允许您向回收视图添加名称,然后开始一轮,通过意向CurrentMatchActivity向Arraylist发送人员。用户输入一段时间后,它通过向新的CurrentMatchActivity传递人员的Arraylist来启动另一个CurrentMatchActivity实例 这是Person类 public class Person implements Parcelable { private String name; private in

让我知道我在做什么。我有一个
主要活动
,允许您向
回收视图添加名称
,然后开始一轮,通过意向
CurrentMatchActivity
Arraylist
发送人员。用户输入一段时间后,它通过向新的
CurrentMatchActivity
传递人员的
Arraylist
来启动另一个
CurrentMatchActivity
实例

这是
Person类

public class Person implements Parcelable {
    private String name;
    private int wins;
    private long totalWins;
    private boolean stillPlaying;
    private ArrayList<Person> previousOpponents;

    Person(String name)
    {
        this.name = name;
        wins = 0;
        totalWins = 0;
        stillPlaying = true;
        previousOpponents = new ArrayList<>();
    }

    public void setStillPlaying(boolean playing)
    {
        stillPlaying = playing;
    }

    public void addOpponent(Person person) {
        previousOpponents.add(person);
    }

    public boolean hasFought(Person person) {
        return previousOpponents.contains(person);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    private Person(Parcel in)
    {
        name = in.readString();
        wins = in.readInt();
        totalWins = in.readLong();
        stillPlaying = (boolean) in.readValue(null);
        previousOpponents = new ArrayList<>();
        in.readTypedList(previousOpponents, null);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeInt(wins);
        dest.writeLong(totalWins);
        dest.writeValue(stillPlaying);
        dest.writeTypedList(previousOpponents);
    }

    public static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {
        public Person createFromParcel(Parcel in) {
            return new Person(in);
        }

        public Person[] newArray(int size) {
            return new Person[size];
        }
    };
}
奇怪的是它工作得很好。除非我激活密码

public void prepareMatch() {
    Collections.shuffle(people);
    int i = 0;
    Person personA;
    Person personB;
    ListIterator<Person> a;

    while (i < (int)(people.size() / 2))
    {
        personA = a.next();
        personB = a.next();
        i++;

        personA.addOpponent(personB);
        personB.addOpponent(personA);
    }
}
public void prepareMatch(){
收藏。洗牌(人);
int i=0;
人物角色;
个人B;
列表迭代器a;
而(i<(int)(people.size()/2))
{
personA=a.next();
personB=a.next();
i++;
添加对手(personB);
人物添加对手(人物角色);
}
}
这会导致
MainAdapter中的
null
指针崩溃

main活动
使用
main适配器
。但是
currentMatchActivity
使用CurrentMatch适配器。。当它试图从
CurrentMatchActivity
创建
CurrentMatchActivity
时,就会发生崩溃

我不认为这里应该使用
MainAdapter
。。。仅限
CurrentMatchAdapter
。此外我不认为激活
prepareMatch
功能会以这种方式影响我的代码流


编辑:发现它正在崩溃,因为
包裹
。我猜它不喜欢人列表中的人列表。

我得出的结论是,问题在于将一个类的arraylist嵌套在同一个类的arraylist中,并使其可打包。我最终在类中使用了int主键的arraylist,它解决了这个问题

例如:

class A implements parcelable {
      arraylist<int> keys;
}


arraylist<a>
A类实现可包裹{
数组列表键;
}
数组表
class A implements parcelable {
      arraylist<int> keys;
}


arraylist<a>