I had tried doing this prior to this without the library and it worked fine. However using the retrofit library i am getting it returned this log:
FATAL EXCEPTION: main Process: com.example.lenovo.retrof, PID: 21218 java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.example.lenovo.retrof.POJO.MainResponse.getResults()' on a null object reference at com.example.lenovo.retrof.MainActivity$1.onResponse(MainActivity.java:53) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
This is my code at the point of crash:
gitrep.enqueue(new Callback<MainResponse>() {
@Override
public void onResponse(Call<MainResponse> call, Response<MainResponse> response) {
if(response == null){
Log.d("place","place id null");
}
else {
for (int i =0; i < response.body().getResults().size(); i++){
String place_id = response.body().getResults().get(i).getPlaceId();
Log.d("place",place_id);
}
}
}
Also this is my MainResponse pojo class
public class MainResponse {
@SerializedName("html_attributions")
@Expose
private List<Object> html_attributions = new ArrayList<Object>();
@SerializedName("next_page_token")
@Expose
private String next_page_token;
@SerializedName("results")
@Expose
private List<Result> results = new ArrayList<Result>();
@SerializedName("status")
@Expose
private String status;
public List<Object> getHtml_attributions() {
return html_attributions;
}
public void setHtml_attributions(List<Object> html_attributions) {
this.html_attributions = html_attributions;
}
public String getNext_page_token() {
return next_page_token;
}
public void setNext_page_token(String next_page_token) {
this.next_page_token = next_page_token;
}
public List<Result> getResults() {
return results;
}
public void setResults(List<Result> results) {
this.results = results;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}