最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年06月11日 14:33:56   投稿:lqh  
這篇文章主要介紹了Android 使用volley過程中遇到的問題解決辦法的相關(guān)資料,需要的朋友可以參考下

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

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

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

錯(cuò)誤提示:com.android.volley.NoConnectionError: java.io.InterruptedIOException”,然后就內(nèi)容加載失敗。。。、

代碼如下:

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 {
   // 發(fā)送請(qǐng)求用到的一些參數(shù)
   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(); //經(jīng)過反復(fù)調(diào)試錯(cuò)誤就出在這里,注釋掉這里就可以了
}

問題出在調(diào)用 queue.start() 方法之后,錯(cuò)誤原因可以通過 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();//這里需要注意,原來在請(qǐng)求初始化的時(shí)候就已經(jīng)調(diào)用了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();
  }
 }
}

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

相關(guān)文章

  • Android 接收推送消息跳轉(zhuǎn)到指定頁面的方法

    Android 接收推送消息跳轉(zhuǎn)到指定頁面的方法

    這篇文章主要介紹了Android 接收推送消息跳轉(zhuǎn)到指定頁面的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android存儲(chǔ)卡讀寫文件與Application數(shù)據(jù)保存的實(shí)現(xiàn)介紹

    Android存儲(chǔ)卡讀寫文件與Application數(shù)據(jù)保存的實(shí)現(xiàn)介紹

    這篇文章主要介紹了Android在存儲(chǔ)卡上讀寫文件、Application保存數(shù)據(jù)的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-09-09
  • Android Kotlin 基本數(shù)據(jù)類型詳解

    Android Kotlin 基本數(shù)據(jù)類型詳解

    Kotlin是一種靜態(tài)類型語言,適用于Android開發(fā),Kotlin的基本數(shù)據(jù)類型包括數(shù)值類型、字符類型、布爾類型和數(shù)組類型,本文介紹Android Kotlin 基本數(shù)據(jù)類型,感興趣的朋友一起看看吧
    2025-03-03
  • Android實(shí)現(xiàn)應(yīng)用內(nèi)置語言切換功能

    Android實(shí)現(xiàn)應(yīng)用內(nèi)置語言切換功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)應(yīng)用內(nèi)置語言切換功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android基于Sqlite實(shí)現(xiàn)注冊(cè)和登錄功能

    Android基于Sqlite實(shí)現(xiàn)注冊(cè)和登錄功能

    這篇文章主要為大家詳細(xì)介紹了Android基于Sqlite實(shí)現(xiàn)注冊(cè)和登錄功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android實(shí)現(xiàn)倒計(jì)時(shí)的按鈕效果

    Android實(shí)現(xiàn)倒計(jì)時(shí)的按鈕效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)倒計(jì)時(shí)的按鈕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • android 處理配置變更的實(shí)現(xiàn)方法

    android 處理配置變更的實(shí)現(xiàn)方法

    這篇文章主要介紹了android 處理配置變更的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-07-07
  • Android MPAndroidChart開源圖表庫之餅狀圖的代碼

    Android MPAndroidChart開源圖表庫之餅狀圖的代碼

    MPAndroidChart是一款基于Android的開源圖表庫,MPAndroidChart不僅可以在Android設(shè)備上繪制各種統(tǒng)計(jì)圖表,而且可以對(duì)圖表進(jìn)行拖動(dòng)和縮放操作,應(yīng)用起來非常靈活
    2018-05-05
  • Android基于OkHttp實(shí)現(xiàn)下載和上傳圖片

    Android基于OkHttp實(shí)現(xiàn)下載和上傳圖片

    這篇文章主要為大家詳細(xì)介紹了Android基于OkHttp實(shí)現(xiàn)下載和上傳圖片功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android中Fragment管理及重疊問題的解決方法

    Android中Fragment管理及重疊問題的解決方法

    最近做項(xiàng)目碰到了Fragment重疊的問題,后來通過種種方法得以解決了,所以想著總結(jié)下這個(gè)問題的解決方法,以及Android中Fragment的管理,方便自己也給有需要的朋友們提供以幫助,感興趣的朋友們下面通過這篇文章一起來學(xué)習(xí)學(xué)習(xí)吧
    2016-11-11

最新評(píng)論

大关县| 高唐县| 涡阳县| 土默特右旗| 兰考县| 句容市| 保亭| 休宁县| 宁河县| 安国市| 松阳县| 栾城县| 彩票| 微山县| 洞口县| 东乌| 南平市| 柳江县| 南部县| 宣威市| 凤翔县| 广平县| 莎车县| 镇安县| 渭源县| 苍溪县| 南雄市| 永嘉县| 娱乐| 耒阳市| 馆陶县| 田东县| 阜宁县| 黔东| 永寿县| 毕节市| 朝阳县| 舞阳县| 亚东县| 关岭| 丹江口市|