gpt4 book ai didi

java - 通过使用parcelable,尝试将一个数组列表添加到另一个数组列表中,出现错误 "the method add is not applicable for the arguments"

转载 作者:行者123 更新时间:2023-12-02 07:59:23 25 4
gpt4 key购买 nike

我有一个 Activity (第一个 Activity ):

ArrayList <MyDouble> myfinals=new ArrayList <MyDouble>();
...
i.putParcelableArrayListExtra("myfinals",myfinals);
...
public static class MyDouble implements Parcelable {
Double al;


public MyDouble(Parcel source){
al = source.readDouble();
}

public MyDouble(Double val){
al = val;
}

@Override
public int describeContents() {
// TODO Auto-generated method stub
return this.hashCode();
}

@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeDouble(al);

}

public Double getValueDouble(){
return this.al;
}
public static final Parcelable.Creator<MyDouble> CREATOR = new Parcelable.Creator<MyDouble>() {

@Override
public MyDouble createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new MyDouble(source);
}

@Override
public MyDouble[] newArray(int size) {
// TODO Auto-generated method stub
return new MyDouble[size];
}
};

}

在其他 Activity 中:

ArrayList <MyDouble> myfinals=new ArrayList <MyDouble>();
ArrayList<Double> y =new ArrayList<Double>();
...
for (int i=0;i<=100;i++){
y.add(myfinals.get(i));

}

我正在尝试将“myfinals”添加到 y 但它给了我错误“添加方法不适用于参数'firstactivity.MyDouble”。

最佳答案

这应该有效:

for (int i=0;i<=100;i++){
y.add(myfinals.get(i).getValueDouble());
}

关于java - 通过使用parcelable,尝试将一个数组列表添加到另一个数组列表中,出现错误 "the method add is not applicable for the arguments",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9130660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com