【问题标题】:Volley Exception throws BroadCastReceiverVolley Exception 引发 BroadCastReceiver
【发布时间】:2013-07-23 12:14:29
【问题描述】:

我正在使用volley library 开发我的项目。

当我解析数据时,如果有任何网络问题或服务器端错误,它有时会抛出错误,我想使用 toast 显示此错误消息,但我无法处理此问题,并且在 volley 错误时不显示任何 toast。所以我想使用广播接收器来管理这个问题。如果可能的话,请给我任何解决这个问题的建议或解决方案。我使用 volley 错误显示 toast 的代码是:

mRequestQueue = Volley.newRequestQueue(context);
JsonObjectRequest jr = new JsonObjectRequest(Request.Method.POST, url, jsonReq,
        new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.i("response", response.toString());

                dataObj.loadData(response);
                if(flag){
                    context.startActivity(intent);
                }
            }
        },
        new Response.ErrorListener() {
            @SuppressLint("ShowToast")
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context, error.toString(), Toast.LENGTH_LONG);
                Log.e("Json parse error", error.toString());
            }
        });

//RequestQueue mRequestQueue = Volley.newRequestQueue(this);
mRequestQueue.add(jr);

【问题讨论】:

  • 究竟是什么问题?是否在错误上调用了 onErrorResponse()?此外,在创建的 toast 上调用 show() 可能有意义。

标签: android android-volley


【解决方案1】:

我想你忘了展示吐司

Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show();

尝试打开 Android Lint,因为它会包括这种情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    相关资源
    最近更新 更多