this is my api call where the error is occuring
public void loadData(){
pd=new ProgressDialog(this);
pd.setMessage("loading");
pd.show();
mApi= new RetrofitHelper<AuthApi>().getApi(AuthApi.class);
mCall=mApi.studentlist(pageNo);
mCall.enqueue(new Callback<ResultObject<ArrayList<Person>>>() {
@Override
public void onResponse(Call<ResultObject<ArrayList<Person>>> call, Response<ResultObject<ArrayList<Person>>> response) {
for(int i=0;i<response.body().getData().size();i++){
mData.add(response.body().getData().get(i));
}
count=response.body().getCount();
mAdapter=new PersonAdapter(Members.this,R.layout.item_person,mData);
list.setAdapter(mAdapter);
pd.hide();
}
@Override
public void onFailure(Call<ResultObject<ArrayList<Person>>> call, Throwable t) {
Toast.makeText(Members.this,"failed",Toast.LENGTH_SHORT).show();
pd.hide();
}
});
}
this is my logcat while caaling an api,as u can see that i get the response correctly and i at the backend traceball and it is fine with no errors
07-01 12:23:56.180 12981-13143/com.example.kethan.project D/OkHttp: --> GET http://192.168.0.107:8000/students/?page=1 http/1.1
07-01 12:23:56.180 12981-13143/com.example.kethan.project D/OkHttp: --> END GET
07-01 12:23:56.183 12981-12981/com.example.kethan.project D/ActivityThreadInjector: clearCachedDrawables.
07-01 12:23:56.261 12981-13143/com.example.kethan.project D/OkHttp: <-- 200 OK http://192.168.0.107:8000/students/?page=1 (80ms)
07-01 12:23:56.261 12981-13143/com.example.kethan.project D/OkHttp: Date: Sat, 01 Jul 2017 06:53:53 GMT
07-01 12:23:56.261 12981-13143/com.example.kethan.project D/OkHttp: Server: WSGIServer/0.2 CPython/3.5.2
07-01 12:23:56.261 12981-13143/com.example.kethan.project D/OkHttp: Content-Length: 849
07-01 12:23:56.261 12981-13143/com.example.kethan.project D/OkHttp: Vary: Accept, Cookie
07-01 12:23:56.261 12981-13143/com.example.kethan.project D/OkHttp: Content-Type: application/json
07-01 12:23:56.261 12981-13143/com.example.kethan.project D/OkHttp: X-Frame-Options: SAMEORIGIN
07-01 12:23:56.262 12981-13143/com.example.kethan.project D/OkHttp: Allow: GET, POST, HEAD, OPTIONS
07-01 12:23:56.263 12981-13143/com.example.kethan.project D/OkHttp: {"count":37,"next":"http://192.168.0.107:8000/students/?page=2","previous":null,"results":[{"id":35,"name":"kethan","mobile":"8142142827","time":"10:5:0","late":"late by: 5mins 0secs","date":"2017/6/16"},{"id":36,"name":"kethan","mobile":"8142142827","time":"23:28:0","late":"late by: 13hrs 28mins 0secs","date":"2017/06/29"},{"id":37,"name":"kethan","mobile":"8142142827","time":"134","late":"123","date":"123"},{"id":38,"name":"kethan","mobile":"8142142827","time":"134","late":"123","date":"123"},{"id":39,"name":"kethan","mobile":"8142142827","time":"134","late":"123","date":"123"},{"id":40,"name":"kethan","mobile":"8142142827","time":"134","late":"123","date":"123"},{"id":41,"name":"kethan","mobile":"8142142827","time":"134","late":"123","date":"123"},{"id":42,"name":"kethan","mobile":"8142142827","time":"134","late":"123","date":"123"}]}
07-01 12:23:56.263 12981-13143/com.example.kethan.project D/OkHttp: <-- END HTTP (849-byte body)
07-01 12:23:56.292 12981-12981/com.example.kethan.project D/AndroidRuntime: Shutting down VM
--------- beginning of crash
07-01 12:23:56.292 12981-12981/com.example.kethan.project E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kethan.project, PID: 12981
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at com.example.kethan.project.Members$2.onResponse(Members.java:108)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
this is the result object
public class ResultObject<T> {
private int count;
private T data;
public int getCount() {
return count;
}
public T getData() {
return data;
}
public void setCount(int count) {
this.count = count;
}
public void setData(T data) {
this.data = data;
}
}
this is the Person pojo class
public class Person {
private int id;
private String time;
private String late;
private String date;
private String name;
private String mobile;
public String getDate() {
return date;
}
public int getId() {
return id;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getLate() {
return late;
}
public void setLate(String late) {
this.late = late;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public void setDate(String date) {
this.date = date;
}
public void setId(int id) {
this.id = id;
}
}