Just starting to use Retrofit, but I have a few doubts. I can´t avoid a few errors which don´t let me debug my app. So sorry for bother you all.
Well, this is the part of the code which maybe you need to know.
As you all see, Graddle, Interface (for Rest), Pojo Class (with class and parent class which is a list of the first one), and the activity (I call retrofit in onCreate, and I recover Data in onResponse)
--Graddle--
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
--Pojo--
public class pisoAlquiler {
private int codigo;
private String fotos;
}
public class pisosAlquiler {
List<pisoAlquiler> pisoAlquilerList;
}
--Interface--
public interface RestApi {
@GET("/Service1.svc?wsdl")
Call<pisosAlquiler> devolverPisosA();
}
--Activity--
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alquiler);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://localhost:52896")
.addConverterFactory(GsonConverterFactory.create())
.build();
// prepare call in Retrofit 2.0
RestApi restApi = retrofit.create(RestApi.class);
Call<pisosAlquiler> call = restApi.devolverPisosA();
//asynchronous call
call.enqueue(this);
}
@Override
public void onResponse(Call<pisoAlquiler> call, Response<pisoAlquiler> response) {
setProgressBarIndeterminateVisibility(false);
// Create a LinearLayout element
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
pisosAlquiler prueba = (pisosAlquiler) response.body().pisoAlquilerList;
}
I´m getting two errors, problably coming from the same issue.
In onCreate:
call.enqueue(this);
this returns error saying in Call cannot be applied, if I use pisoAlquiler Class, instead of pisosAlquiler (which contains a list of pisoAlquiler) the error dissapear.
In onResponse:
pisosAlquiler prueba = (pisosAlquiler) response.body().pisoAlquilerList;
pisoAlquilerList returns cannot resolve symbol. Looks like I can call attributes of pisoAlquiler but not the only attribute which pisosAlquiler has it...
Any Ideas?
Thanks Mates.