91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android 使用volley過程中遇到的問題解決辦法

發布時間:2020-09-12 23:31:23 來源:腳本之家 閱讀:339 作者:lqh 欄目:移動開發

Android 使用volley過程中遇到的問題解決辦法

本文主要介紹使用 volley 過程中遇到的問題,錯誤提示:

com.android.volley.NoConnectionError: java.io.InterruptedIOException”,內容加載失敗,問題出在重復調用 queue.start() 方法。

錯誤提示:com.android.volley.NoConnectionError: java.io.InterruptedIOException”,然后就內容加載失敗。。。、

代碼如下:

private void getWxpayOrderInfo() {
 StringRequest stringRequest = new StringRequest(Request.Method.POST,
 Url, new Response.Listener<String>() {
  @Override
  public void onResponse(String response) {
  }
 }, new Response.ErrorListener() {
  @Override
  public void onErrorResponse(VolleyError error) {
  }
 }) {
  @Override
  protected Map<String, String> getParams()
  throws AuthFailureError {
   // 發送請求用到的一些參數
   Map<String, String> params = new HashMap<String, String>();
   params.put("id", "nameid");
   return params;
  }
 };
 stringRequest.setRetryPolicy(new DefaultRetryPolicy(10000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
 queue.add(stringRequest);
 //queue.start(); //經過反復調試錯誤就出在這里,注釋掉這里就可以了
}

問題出在調用 queue.start() 方法之后,錯誤原因可以通過 volley 源文件看到,以下是 volley 官方文檔中初始化 RequestQueue 的一段代碼。

/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack  An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
 File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
 String userAgent = "volley/0";
 try {
  String packageName = context.getPackageName();
  PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
  userAgent = packageName + "/" + info.versionCode;
 } catch (NameNotFoundException e) {
 }
 if (stack == null) {
  if (Build.VERSION.SDK_INT >= 9) {
   stack = new HurlStack();
  } else {
   // Prior to Gingerbread, HttpUrlConnection was unreliable.
   // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
   stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
  }
 }
 Network network = new BasicNetwork(stack);
 RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
 queue.start();//這里需要注意,原來在請求初始化的時候就已經調用了start方法
 return queue;
}
 
/**
 * Starts the dispatchers in this queue.
 */
public void start() {
 stop(); // Make sure any currently running dispatchers are stopped.
 // Create the cache dispatcher and start it.
 mCacheDispatcher = new CacheDispatcher(mCacheQueue, mNetworkQueue, mCache, mDelivery);
 mCacheDispatcher.start();
 // Create network dispatchers (and corresponding threads) up to the pool size.
 for (int i = 0; i < mDispatchers.length; i++) {
  NetworkDispatcher networkDispatcher = new NetworkDispatcher(mNetworkQueue, mNetwork,
    mCache, mDelivery);
  mDispatchers[i] = networkDispatcher;
  networkDispatcher.start();
 }
}
 
/**
 * Stops the cache and network dispatchers.
 */
public void stop() {
 if (mCacheDispatcher != null) {
  mCacheDispatcher.quit();
 }
 for (int i = 0; i < mDispatchers.length; i++) {
  if (mDispatchers[i] != null) {
   mDispatchers[i].quit();
  }
 }
}
 
/**
* Forces this dispatcher to quit immediately. If any requests are still in
* the queue, they are not guaranteed to be processed.
*/
public void quit() {
 mQuit = true;
 interrupt();
}
 
public void interrupt() {
 // Interrupt this thread before running actions so that other
 // threads that observe the interrupt as a result of an action
 // will see that this thread is in the interrupted state.
 nativeInterrupt();
 synchronized (interruptActions) {
  for (int i = interruptActions.size() - 1; i >= 0; i--) {
   interruptActions.get(i).run();
  }
 }
}

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

黎城县| 清涧县| 全南县| 故城县| 深州市| 太保市| 慈利县| 左权县| 惠安县| 行唐县| 屏南县| 潞西市| 渭源县| 平湖市| 清水县| 正蓝旗| 仙居县| 南陵县| 长兴县| 鱼台县| 青龙| 广河县| 印江| 宕昌县| 札达县| 和静县| 博罗县| 聊城市| 阳原县| 尼勒克县| 隆德县| 华蓥市| 邹平县| 新巴尔虎左旗| 昂仁县| 浦城县| 平安县| 兴化市| 昆明市| 麦盖提县| 新巴尔虎右旗|