URL Link : http://www.factsplanet.info/cities.php Method Retrofit Error: java.lang.IllegalArgumentException
Main Class
public class MainActivity extends AppCompatActivity {
Retrofit retrofit;
Factory service;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
retrofit = new Retrofit.Builder()
.baseUrl("https://factsplanet.info/")
.build();
service = retrofit.create(Factory.class);
Call<ThisIsPojo> call = service.getnames();
call.enqueue(new Callback<ThisIsPojo>() {
@Override
public void onResponse(Response<ThisIsPojo> response, Retrofit retrofit) {
Toast.makeText(MainActivity.this, response.body().getData().get(1).getCountry(), Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Throwable t) {
}
});
}
}
Interface Class:
public interface Factory {
@GET ("http://www.factsplanet.info/cities.php")
Call<ThisIsPojo> getnames();
}
POJO CLASS:
public class ThisIsPojo {
private List<Datum> data = null;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public List<Datum> getData() {
return data;
}
public void setData(List<Datum> data) {
this.data = data;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
Error Says: java.lang.RuntimeException: Unable to start activity
java.lang.IllegalArgumentException: Unable to create converter for class app.com.alphaapps.android.suntest.pojo.ThisIsPojo for method Factory.getnames
Modify it like this:
retrofit = new Retrofit.Builder().baseUrl("https://factsplanet.info/").addConverterFactory(GsonConverterFactory.create()).build();