0

i have a problem with Retrofit2 on a real device , however it works on the emulator , the reponse body is null when i use my Samsung J7 2016 or any other device , i noticed that my response code is 403 using phpmyadmin(localhost ) with my phone instead of 200 with an emulator .

           OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .connectTimeout(1, TimeUnit.MINUTES)
            .readTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(15, TimeUnit.SECONDS)
            .build();
    Retrofit adapter = new Retrofit.Builder()
            .baseUrl(ROOT_URL)
            .client(okHttpClient)             
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    MyService myService = adapter.create(MyService.class);
    retrofit2.Call<Result> call = myService.connectUser(email,password);
    call.enqueue(new retrofit2.Callback<Result>() {
        @Override
        public void onResponse(retrofit2.Call<Result> call, retrofit2.Response<Result> response) {

            ArrayList<HashMap<String,String>> results = response.body().getData();
        .
        .
        .

         }

        @Override
        public void onFailure(retrofit2.Call<Result> call, Throwable t) {

            showMessage("ERROOR "+ t.getMessage());
            finish();
        }

it returns :

        java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.ArrayList com.example.jamal.mysqlretrofit.results.Result.getData()' on a null object reference

but it works in genymotion emulator's , can you help please !

1 Answers1

0

i have fixed the issu , the solution for me was to change :

       # onlineoffline tag - don't remove
       Order Deny,Allow
       Deny from all
       Allow from 127.0.0.1
       Allow from ::1
       Allow from localhost

to :

       #   onlineoffline tag - don't remove
             Require local
             Require ip 192.168.0

the response was here : WAMP Cannot access on local network 403 Forbidden thanks every one .