从json加载图片的问题/为什么我的位图为空?

时间:2014-06-11 18:45:01

标签: android json bitmap android-asynctask bitmapimage

我一直在努力理解为什么我的位图为空,但到目前为止我无法做到这一点。这就是我的模型中的内容:

 public Bitmap getBitmapFromUrl(String imageURL) {

    Bitmap bitmap = null;
    HttpGet httpRequest = null;
    HttpClient httpclient = new DefaultHttpClient();

    try {
        URL urlImage = new URL(imageURL);
        httpRequest = new HttpGet(urlImage.toURI());
        HttpResponse httpResponse = (HttpResponse) httpclient.execute(httpRequest);

        HttpEntity entity = httpResponse.getEntity();
        BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
        InputStream input = b_entity.getContent();

        bitmap = BitmapFactory.decodeStream(input);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    System.out.println(bitmap);
    return bitmap;
}

这就是我onPostExecute AsyncTask中的protected void onPostExecute(JSONArray json) { dialog.dismiss(); Intent intent = getIntent(); Bundle extras = intent.getExtras(); position = extras.getString("position"); int positionInt = Integer.parseInt(position); String price = ""; String description = ""; String image = ""; try { JSONObject ad = json.getJSONObject(positionInt); price = ad.getString("price"); description = ad.getString("description"); image = ad.getString("image"); } catch (JSONException ex) { ex.printStackTrace(); } TextView viewPrice = (TextView) findViewById(R.id.ad_view_price); viewPrice.setText(price); TextView viewDescription = (TextView) findViewById(R.id.ad_view_description); viewDescription.setText(description); final String imageURL = "http://192.168.0.16:3000" + image; Bitmap bitmap = jParser.getBitmapFromUrl(imageURL); System.out.println(bitmap); img = (ImageView) findViewById(R.id.ad_view_photo_image); img.setImageBitmap(bitmap); super.onPostExecute(json); }

{{1}}

先谢谢你的帮助!!

0 个答案:

没有答案