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 !