凌空抛出异常的BroadcastReceiver [英] Volley Exception throws BroadCastReceiver

查看:148
本文介绍了凌空抛出异常的BroadcastReceiver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用凌​​空库

当我分析的数据,它抛出错误的某个时候,如果任何网络问题或服务器端错误,我想显示使用敬酒此错误消息,但我不能处理这一点,并没有表现出对抽射错误的任何敬酒。所以我想用广播接收器来管理这个问题。如果可能的话,请给我任何建议或解决方案,解决了这个问题。显示吐司上使用凌空错误我的code是:

  mRequestQueue = Volley.newRequestQueue(上下文);
JsonObjectRequest JR =新JsonObjectRequest(Request.Method.POST,网址,jsonReq,
        新Response.Listener<的JSONObject>(){
            @覆盖
            公共无效onResponse(JSONObject的响应){
                Log.i(回应,response.toString());

                dataObj.loadData(响应);
                如果(旗){
                    context.startActivity(意向);
                }
            }
        },
        新Response.ErrorListener(){
            @燮pressLint(ShowToast)
            @覆盖
            公共无效onErrorResponse(VolleyError错误){
                Toast.makeText(上下文,error.toString(),Toast.LENGTH_LONG);
                Log.e(Json的解析错误,error.toString());
            }
        });

//请求队列mRequestQueue = Volley.newRequestQueue(本);
mRequestQueue.add(JR);
 

解决方案

我想你忘记显示敬酒

  Toast.makeText(背景下,error.toString(),Toast.LENGTH_LONG).show();
 

试图把在Android林特,因为它将你很多,包括这种情况。

I am developing my project using volley library.

When I parse data it throws error sometime if any network problem or server side error, I want to display this error message using toast but I can't handle this and not show any toast on error of volley. So I want to manage this problem using broadcast receiver. If it possible then please give me any suggestion or solution for solve this problem. My code of display toast on error using volley is:

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);

解决方案

I think you forgot to show toast

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

Trying to turn on Android Lint as it will you a lot including this case.

这篇关于凌空抛出异常的BroadcastReceiver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆