Problem with RetroFit Return on Android

0

I'm trying to connect to the local network, using RetroFit . On the local network I have a Rest that returns a json, but when I run the event for this to happen, an error occurs

I have an interface class for RetroFit

public interface iRetroFitSibcom {

    @GET("/{categoria}")
    Call<List<Categoria>> getCategorias(@Path("categoria") String categoria); 

    public static final Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://10.0.2.2:8080/sibcomslim")
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

And a button where the event occurs

@Override
public void onClick(View v) {
    iRetroFitSibcom githubUser = iRetroFitSibcom.retrofit.create(iRetroFitSibcom.class);
    final Call <List<Categoria>> call = githubUser.getCategorias("categorias");
    call.enqueue(new Callback<List<Categoria>>() {
        @Override
        public void onResponse(Call<List<Categoria>> call, Response<List<Categoria>> response) {
            int code = response.code();
            if (code == 200) {
                List<Categoria> lista = response.body();
                for (Categoria categoria : lista) {
                    Log.d("MainActivity", categoria.descricao);
                }
            }
            else {
                Toast.makeText(getBaseContext(), "Falha: " + String.valueOf(code),
                Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onFailure(Call<List<Categoria>> call, Throwable t) {

        }
    });
}

But when I do this nothing happens, no error message appears or the descriptions are displayed in Log.d.

However, the following information is loaded

  

08-21 14: 41: 59,637 6491-6491 / dev.sbruno.sibcom I / Choreographer:   Skipped 36 frames! The application may be doing a lot of work on its   main thread.   08-21 14: 42: 04.622 6491-6491 / dev.sbruno.sibcom   D / NetworkSecurityConfig: No Network Security Config specified, using   platform default   08-21 14: 42: 17,388 6491-6496 / dev.sbruno.sibcom I / art:   From the partial code cache collection, code = 30KB, date = 28KB 08-21   14: 42: 17,391 6491-6496 / dev.sbruno.sibcom I / art: After code cache   collection, code = 23KB, data = 25KB 08-21 14: 42: 17,391   6491-6496 / dev.sbruno.sibcom I / art: Increasing code cache capacity to   128KB

What's going wrong? even trying to debug I can not do it because it is not possible to access the lines that I put to debug, it does not even reach them

Edit

I just added a Toast to onFailure and I checked that the code is going through there, so there should be some connection error is that?

@Override
public void onFailure(Call<List<Categoria>> call, Throwable t) {
      Toast.makeText(getBaseContext(), "Falhou ao me conectar ",
      Toast.LENGTH_LONG).show();
    
asked by anonymous 21.08.2017 / 16:46

0 answers