ボレーのRequestFutureクラスを使用しているときに問題が発生しています。wait(0)
実際には;で止まります。以下のRequestFutureクラスの関数内で、または私がそうすべきだと思うようにdoGet()
目覚めることはありません。onResponse
onErrorResponse
private synchronized T doGet(Long timeoutMs)
throws InterruptedException, ExecutionException, TimeoutException {
if (mException != null) {
throw new ExecutionException(mException);
}
if (mResultReceived) {
return mResult;
}
if (timeoutMs == null) {
wait(0);
} else if (timeoutMs > 0) {
wait(timeoutMs);
}
if (mException != null) {
throw new ExecutionException(mException);
}
if (!mResultReceived) {
throw new TimeoutException();
}
return mResult;
}
@Override
public boolean isCancelled() {
if (mRequest == null) {
return false;
}
return mRequest.isCanceled();
}
@Override
public synchronized boolean isDone() {
return mResultReceived || mException != null || isCancelled();
}
@Override
public synchronized void onResponse(T response) {
mResultReceived = true;
mResult = response;
notifyAll();
}
@Override
public synchronized void onErrorResponse(VolleyError error) {
mException = error;
notifyAll();
}
これは、上記のすべてを呼び出す方法です。
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest myReq = new JsonObjectRequest(Request.Method.POST, url, jsonObj, future, future);
requestQueue.add(myReq);
try {
JSONObject response = future.get();
} catch (InterruptedException e) {
// handle the error
} catch (ExecutionException e) {
// handle the error
}
ラインも交換してみた
requestQueue.add(myReq);
と
future.setRequest(requestQueue.add(myReq));
また
future.setRequest(myReq);
どちらも役に立ちませんでした。
このパラメーターを使用して正常に機能する通常の Volley Request を既に試したので、それが原因ではないはずです。問題は、リクエストが実際に実行されないことだと思います。これが、レスポンスリスナーに到達しない理由です。も試しrequestQueue.start()
ましたが、何も変わりませんでした。
問題を十分に説明できれば幸いです。よろしくお願いします。