android之volley StringRequest null

来源:互联网 发布:adams四连杆优化 编辑:程序博客网 时间:2024/04/28 05:34

在android网络请求时,经常用Google2013年新出的volley,

今天在用的过程中,在创建StringRequest时,一直报空指针的异常,非常郁闷. 


楼主就研究了一下,下面是官方代码的方法.

 public Request(int method, String url, Response.ErrorListener listener) {
        mMethod = method;
        mUrl = url;
        mErrorListener = listener;
        setRetryPolicy(new DefaultRetryPolicy());


        mDefaultTrafficStatsTag = TextUtils.isEmpty(url) ? 0: Uri.parse(url).getHost().hashCode();
    }

传入的url,在Uri.parse(url).getHost().hashCode()进行截取,如果我们输入的url没有带"http://"就会报错

0 0