I am new to Retrofit . i am trying to call api using base url,but i getting error while loading function.there is a object and inside that there is two different arrays name animal and birds.i need to call this array from the object and need to load in gridview adapter. this is how i calling the function in my fragment.
My error.
java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.
for method GetDataService.getAll
This is my JSON response
{ "animals": [ { "animalName": "String", "animalID": "integer", } ], "birds": [ { "birdsId": "integer", "birdsname": "string } ], "ID": "integer" }
Calling GET in fragment
Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://demoapp.in/") .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); GetDataService service = retrofit.create(GetDataService .class); Call<TableResponse> call= service.getAll(new TableResponse()); call.enqueue(new Callback<TableResponse>() { @Override public void onResponse(Call<TableResponse> call, Response<TableResponse> response) { String passKey = response.body().getPassKey(); List<Table> TableName = response.body().getTables(); String[] TableNameArray = new String[TableName.size()]; for (int i = 0; i < TableName.size(); i++) { TableNameArray[i] = TableName.get(i).getTableName(); } gridView.setAdapter(new TableViewAdapter(getContext(), TableNameArray)); } @Override public void onFailure(Call<TableResponse> call, Throwable t) { } });
3.TableResponse,java class in this fie is generated using jsonschema2pojo
@SerializedName("animal")
@Expose
private List<Table> animal = null;
......
public TableResponse(){
this.animal= animal;
this.birds= birds;
this.ID = ID;
}
public List<Table> getTables() {
return tables;
}
-------
4.GetDataService.java
@GET("Animal.ashx")
Call<TableResponse> getAll(@Body TableResponse tableResponse);