How do I bring information from a vector into another vector in json format for the retrofit:
I have my feedback:
[
[
{"prato":"BROCOLIS C\/ SALSINHA"},
{"prato":"ACELGA"},
{"prato":"ALFACE + JERIMUM COZIDO"}
],
[
{"prato":"QUICHE DE ALHO PORO"},
{"prato":"ENSOPADO DE FEIJ?O BRANCO"}
],
[
{"prato":"ARROZ BRANCO"},
{"prato":"FEIJ?O CARIOCA"},
{"prato":"ARROZ INTEGRAL"}
],
[
{"prato":"CALDO VERDE"}
]
]
My interface
@GET("nutricao/")
Call<Pratos> getListPratos(
@Query("acao") String acao,
@Query("tipo_refeicao") int tipo,
@Query("data") String data);
My Model
public class Pratos {
@SerializedName("pratos")
private ArrayList<Prato> pratos;
public ArrayList<Prato> getPratos() {
return pratos;
}
public void setPratos(ArrayList<Prato> pratos) {
this.pratos = pratos;
}
}
Continuation:
public class Prato {
@SerializedName("prato")
private String prato;
public String getPrato() {
return prato;
}
public void setPrato(String prato) {
this.prato = prato;
}
public String toString(){
return prato;
}
}
My attempt to show:
Call<Pratos> listPratos = service.getListPratos("P", 5, "01/08/2017");
listPratos.enqueue(new Callback<Pratos>() {
@Override
public void onResponse(Call<Pratos> call, Response<Pratos> response) {
Log.i("onResponse Pratos",response.toString());
Pratos pratosResponse = response.body();
if( pratosResponse != null ){
ArrayList<Prato> listaPratos = pratosResponse.getPratos();
for(int i = 0; i < listaPratos.size(); i++ ){
Log.i("Prato", listaPratos.get( i ).toString());
}
}
}
@Override
public void onFailure(Call<Pratos> call, Throwable t) {
Log.i("onFailure Prato", t.getMessage());
}
});
}
Only you are giving this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size () 'on a null object reference