我在真实设备上遇到Retrofit2的问题,但它可以在模拟器上运行, 当我使用我的三星J7 2016或任何其他设备时,响应主体为空,我注意到我的响应代码是403使用phpmyadmin(localhost)和我的手机而不是200使用模拟器。
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();
}
它返回:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.ArrayList com.example.jamal.mysqlretrofit.results.Result.getData()' on a null object reference
但它适用于genymotion模拟器,你能帮忙吗?
答案 0 :(得分:0)
我已修复了issu,我的解决方案是改变:
# onlineoffline tag - don't remove
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
到:
# onlineoffline tag - don't remove
Require local
Require ip 192.168.0
回复在这里:WAMP Cannot access on local network 403 Forbidden 谢谢你们。