我正在尝试使用Volley发出同步请求,以便可以返回从mySQL返回的placeid
。但是我得到了TimeoutException
,但我不知道如何解决它。
这是我的日志:
I / VOLLEY:请求已添加
I / VOLLEY:log3java.util.concurrent.TimeoutException
I /编舞:跳过59帧!该应用程序可能在其主线程上做过多的工作。
V / FA:记录用户参与度,毫秒:102327
V / FA:连接到远程服务
V / FA:活动已暂停,时间:1669661030
D / FA:记录事件(FE):user_engagement(_e),捆绑包[{firebase_event_origin(_o)=自动,engage_time_msec(_et)= 102327,firebase_screen_class(_sc)= CreatePlace2,firebase_screen_id(_si)= 2868648022380701827}]]
V / FA:连接尝试正在进行中
D / FA:已连接到远程服务
V / FA:处理排队的服务任务:2
V / FA:处于不活动状态,与服务断开连接
这是我的代码:
public JSONObject createPlaces(final String PlaceName, final int PlaceCategory, final Double PlaceLatitude
, final Double PlaceLongitude, final String NpcId) {
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, Constants.URL_PLACES_CREATE, new JSONObject(),
future,future) {
@Override
protected Map<String, String> getParams () throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("placename", PlaceName);
params.put("categoryid", String.valueOf(PlaceCategory));
params.put("placelat", String.valueOf(PlaceLatitude));
params.put("placelng", String.valueOf(PlaceLongitude));
params.put("npcid", String.valueOf(NpcId));
return params;
}
};
RequestHandler.getInstance(mCtx).addToRequestQueue(request);
Log.i("VOLLEY","request added");
try {
JSONObject response = future.get(1, TimeUnit.SECONDS); // this will block
Log.i("VOLLEY","log"+response);
return response;
} catch (InterruptedException e) {
// exception handling
future.onErrorResponse(new VolleyError(e));
Log.i("VOLLEY","log1"+e);
} catch (ExecutionException e) {
// exception handling
future.onErrorResponse(new VolleyError(e));
Log.i("VOLLEY","log2"+e);
} catch (TimeoutException e) {
future.onErrorResponse(new VolleyError(e));
Log.i("VOLLEY","log3"+e);
}
return null;
}