如何使用Volley读取xml响应中的整数内容?

时间:2019-04-02 06:05:44

标签: android soap

我的回应为<int xmlns="http://tempuri.org/">3</int>。当我尝试在凌空环境中使用StringRequest进行获取时,出现了Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference异常。有什么办法吗 我可以使用凌空从xml获取整数值。这是我的代码

StringRequest volleyReq = new 
             StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {

                            Toast.makeText(getActivity(), finalMsg,Toast.LENGTH_SHORT).show();


                        } catch (Exception e) {
                            e.printStackTrace();
                            Crashlytics.logException(e);

                            showErrorlayoutwithBtn(Global.SERVER_OUT_OF_REACH);

                        }
                    }
                },

                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError err) {
                        Log.e("Error in time json", err.getMessage());
                        err.printStackTrace();
                        //pbInOut.setVisibility(View.GONE);
                        ShowCustomToast(errorToast, Global.FAILURE_RETROFIT);
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> map = new HashMap<>();
                map.put("UserID", usrId);
                map.put("latitude", latitude);
                map.put("longitude", longitude);
                return map;
            }
        };
        volleyReq.setRetryPolicy(new DefaultRetryPolicy(
                2000,
                5,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        MyApplication.getInstance().addToRequestQueue(volleyReq);

这是我的堆栈跟踪

  

2019-04-02 11:01:13.650 6595-6649 / com.hrdelight.android.hrdelight   E / Volley:[288] NetworkDispatcher.processRequest:未处理的异常   java.lang.NullPointerException:尝试调用虚拟方法'int   空对象引用上的java.lang.String.length()'       java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'int java.lang.String.length()'           在java.net.URLEncoder.encode(URLEncoder.java:204)           在com.android.volley.Request.encodeParameters(Request.java:491)           在com.android.volley.Request.getBody(Request.java:477)           在com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:245)           在com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:219)           在com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:97)           在com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)           在com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)           在com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)

有什么办法吗 我可以使用齐射从xml中获取整数值

0 个答案:

没有答案