流转的年华 2015-08-24 00:41 采纳率: 0%
浏览 2855
已采纳

Android 链接服务器获取json数据,解析头像url后。。。

Android 刚进入页面,链接服务器获取json数据,解析图片url,然后联网加载头像图片的操作得不到头像。代码如下。向各位请教。新手,不知道哪里出问题了。
JsonObjectRequest request=new JsonObjectRequest(Request.Method.POST, url, null, new Listener() {

        @Override
        public void onResponse(JSONObject response) {

            JSONObject result;
            String stringUrl = null;
            try {
                result = response
                        .getJSONObject("Result");
                acount = result.getString("Account");
                name = result.getString("UserName");
                stringUrl=result.getString("ImagUrl");
                 String imapath="http://192.168.1.1/"+stringUrl;

                            URL imgUrl=new URL(imapath);
                             HttpURLConnection conn = (HttpURLConnection) imgUrl
                                        .openConnection();
                             Toast.makeText(MyInformationActivity.this, "链接成功", Toast.LENGTH_SHORT).show();
                              conn.connect();
                              InputStream is = conn.getInputStream();
                              Bitmap bm = BitmapFactory.decodeStream(is);

                              ivHeadImage.setImageBitmap(bm);
                              is.close();
                        } catch (Exception e) {
                            Toast.makeText(MyInformationActivity.this, "头像获取异常", Toast.LENGTH_SHORT).show();
                            e.printStackTrace();
                        }

                    }
                  };
            } 
            tvNickName.setText(name);

        }


    }, new ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {


        }
    });
    queue.add(request);

  • 写回答

4条回答 默认 最新

  • oyljerry 2015-08-24 11:26
    关注

    估计你ajax等获取的图片URL地址不正确,导致后面显示不对。你先要确保你的服务器返回了正确的URL等信息

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?