Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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
Android 使用改型getting error解析在arraylist中包含另一个pojo类的pojo类时_Android_Retrofit - Fatal编程技术网

Android 使用改型getting error解析在arraylist中包含另一个pojo类的pojo类时

Android 使用改型getting error解析在arraylist中包含另一个pojo类的pojo类时,android,retrofit,Android,Retrofit,我已经创建了两个模型类,当我得到响应时,我得到了0大小的ArrayList package com.jdb.shopname.Model; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import java.util.List; public class Registration { @SerializedName("success") @Exp

我已经创建了两个模型类,当我得到响应时,我得到了0大小的ArrayList

package com.jdb.shopname.Model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.List;

public class Registration {


@SerializedName("success")
@Expose
private String success;


@SerializedName("data")
@Expose
private List<Datum> data = null;


@SerializedName("msg")
@Expose
private String msg;

public String getSuccess() {
    return success;
}

public void setSuccess(String success) {
    this.success = success;
}

public List<Datum> getData() {
    return data;
}

public void setData(List<Datum> data) {
    this.data = data;
}

public String getMsg() {
    return msg;
}

public void setMsg(String msg) {
    this.msg = msg;
}

}
我称之为改造的主要课程是:

 public void setData(){
    Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .baseUrl(API_URL)
            .build();

    Apiinterface apiinterface = retrofit.create(Apiinterface.class);
    Call<MultipleProductList> call = apiinterface.sendMultipleProducts();
    call.enqueue(new Callback<MultipleProductList>() {
        @Override
        public void onResponse(Call<MultipleProductList> call, Response<MultipleProductList> response) {
            response.body();

            String success = response.body().getSuccess();
            String message = response.body().getMsg();
            Log.e("success", success);
            Log.e("msg", message);

            if (response.isSuccessful()) {
                String responseData = response.body().toString();
                Log.e("here", "onResponse: " + responseData);

             MultipleProductList   multipleProductList = new MultipleProductList();
                multipleProductList.getData();

                List<DataProduct> arrayList = new ArrayList<>();
                arrayList = multipleProductList.getData();





                arrayList.size();

                String id = arrayList.get(0).getID();
                String regularPrice = arrayList.get(0).getRegularPrice();
                String sale_price = arrayList.get(0).getSalePrice();


                Log.e("regularPrice", regularPrice);
                Log.e("sale_price", sale_price);

            } else {
                Log.i("debug", "onResponse: GA BERHASIL");
            }


        }

        @Override
        public void onFailure(Call<MultipleProductList> call, Throwable t) {

            if (t instanceof IOException) {
                Toast.makeText(MainActivity.this, "this is an actual network failure :( inform the user and possibly retry", Toast.LENGTH_SHORT).show();
                // logging probably not necessary
            } else {
                Toast.makeText(MainActivity.this, "conversion issue! big problems :(", Toast.LENGTH_SHORT).show();
                //here                  // todo log to some central bug tracking service
            }

        }
    });


}
public void setData(){
改装改装=新改装.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(API_URL)
.build();
Apiinterface Apiinterface=reformation.create(Apiinterface.class);
Call Call=apinterface.sendMultipleProducts();
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
响应。body();
字符串success=response.body().getSuccess();
字符串消息=response.body().getMsg();
Log.e(“成功”,成功);
Log.e(“msg”,消息);
if(response.issusccessful()){
字符串responseData=response.body().toString();
Log.e(“此处”、“onResponse:+responseData”);
MultipleProductList MultipleProductList=新的MultipleProductList();
multipleProductList.getData();
List arrayList=新建arrayList();
arrayList=multipleProductList.getData();
arrayList.size();
String id=arrayList.get(0.getID();
String regularPrice=arrayList.get(0.getRegularPrice();
字符串sale_price=arrayList.get(0).getSalePrice();
Log.e(“正规价格”,正规价格);
Log.e(“销售价格”,销售价格);
}否则{
Log.i(“调试”,“onResponse:GA BERHASIL”);
}
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
if(IOException的t实例){
Toast.makeText(MainActivity.this,“这是一个实际的网络故障:(通知用户并可能重试)”,Toast.LENGTH_SHORT.show();
//可能不需要记录日志
}否则{
Toast.makeText(MainActivity.this,“转换问题!大问题:(”,Toast.LENGTH_SHORT).show();
//此处//todo登录到某个中央错误跟踪服务
}
}
});
}

response.body返回您使用的MultipleProductList类型的数据

if (response.isSuccessful()) {
                String responseData = response.body().toString();
                Log.e("here", "onResponse: " + responseData);

             MultipleProductList   multipleProductList = response.body;
                multipleProductList.getData();

                List<DataProduct> arrayList = new ArrayList<>();
                arrayList = multipleProductList.getData();





                arrayList.size();

                String id = arrayList.get(0).getID();
                String regularPrice = arrayList.get(0).getRegularPrice();
                String sale_price = arrayList.get(0).getSalePrice();


                Log.e("regularPrice", regularPrice);
                Log.e("sale_price", sale_price);

            } else {
                Log.i("debug", "onResponse: GA BERHASIL");
            }
if(response.issusccessful()){
字符串responseData=response.body().toString();
Log.e(“此处”、“onResponse:+responseData”);
MultipleProductList MultipleProductList=response.body;
multipleProductList.getData();
List arrayList=新建arrayList();
arrayList=multipleProductList.getData();
arrayList.size();
String id=arrayList.get(0.getID();
String regularPrice=arrayList.get(0.getRegularPrice();
字符串sale_price=arrayList.get(0).getSalePrice();
Log.e(“正规价格”,正规价格);
Log.e(“销售价格”,销售价格);
}否则{
Log.i(“调试”,“onResponse:GA BERHASIL”);
}

getting arrayList.size=0在这里发布json文件?至少现在你可以接受我的答案了?当然你可以接受答案,只是你还不能投票。
if (response.isSuccessful()) {
                String responseData = response.body().toString();
                Log.e("here", "onResponse: " + responseData);

             MultipleProductList   multipleProductList = response.body;
                multipleProductList.getData();

                List<DataProduct> arrayList = new ArrayList<>();
                arrayList = multipleProductList.getData();





                arrayList.size();

                String id = arrayList.get(0).getID();
                String regularPrice = arrayList.get(0).getRegularPrice();
                String sale_price = arrayList.get(0).getSalePrice();


                Log.e("regularPrice", regularPrice);
                Log.e("sale_price", sale_price);

            } else {
                Log.i("debug", "onResponse: GA BERHASIL");
            }