0

尝试将 5 个 JSONarrays 添加到 arraylist 但收到此错误

The method add(AllMessageObject) in the type ArrayList<AllMessageObject> is not applicable for the arguments (String)

在这里,我正在放置代码以将 jsonarray 添加到 arraylist.how 来修复它。

for (int j = 0; j < a; j++) {
listdata  = new ArrayList<AllMessageObject>();

listdata.add(jsonArray.get(j).toString());

}

AllMessageObject 是一个类,这里​​是我对该类的代码。listdata 是我的数组列表ArrayList<AllMessageObject> listdata = null; ,我希望这段代码就足够了,如果你需要更多,我会在这里提供。

public class AllMessageObject {

// for getting comment
public String message;
public String from_name;
public String message_date;

// for getting picture 
public String picture_url;
public Bitmap picturein_bitmap;

// for getting my profile image
public String fromprofile_url;
//public Bitmap fromprofileurl_bitmap;


public String getFromprofile_url() {
    return fromprofile_url;
}
public void setFromprofile_url(String fromprofile_url) {
    this.fromprofile_url = fromprofile_url;
}
/*public Bitmap getFromprofileurl_bitmap() {
    return fromprofileurl_bitmap;
}
public void setFromprofileurl_bitmap(Bitmap fromprofileurl_bitmap) {
    this.fromprofileurl_bitmap = fromprofileurl_bitmap;
}*/
public Bitmap getPicturein_bitmap() {
    return picturein_bitmap;
}
public void setPicturein_bitmap(Bitmap picturein_bitmap) {
    this.picturein_bitmap = picturein_bitmap;
}
public String getPicture_url() {
    return picture_url;
}
public void setPicture_url(String picture_url) {
    this.picture_url = picture_url;
}
public String getMessage() {
    return message;
}
public void setMessage(String message) {
    this.message = message;
}
public String getFrom_name() {
    return from_name;
}
public void setFrom_name(String from_name) {
    this.from_name = from_name;
}
public String getMessage_date() {
    return message_date;
}
public void setMessage_date(String message_date) {
    this.message_date = message_date;
}



}
4

1 回答 1

0

您正在尝试放入StringArrayList AllMessageObjectArrayList此外,每次循环运行时您都会分配新的,您将失去以前添加的值。

所以改为这样尝试:

listdata  = new ArrayList<String>();
for (int j = 0; j < a; j++) {   
    listdata.add(jsonArray.get(j).toString());
}
于 2013-11-13T13:24:36.393 回答