解决方案 »

  1.   

    你不是conn都没有链接上么,,,
      

  2.   

    连接网络的代码都要放在子线程里,
    util类的代码::
    /**
     * 根据url获得图片来源
     * 
     * @param url
     *            完整的可访问的url
     * @return Bitmap
     * @throws Exception
     */
    public Bitmap getBitmap(String url) {
    try {
    Log.e(Constant.TAG_NAME, "开始下载图片:" + url);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.connect();
    InputStream input = conn.getInputStream();
    Bitmap bitmap = BitmapFactory.decodeStream(input);
    input.close();
    conn.disconnect();
    return bitmap;
    } catch (Exception e) {
    Log.e(Constant.TAG_NAME, "根据url获得图片来源", e);
    return null;
    }
    }
    activity的代码:private Bitmap bitmap;
    @Override
    protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_scanner_card);
    new Thread() {
    public void run() {
    bitmap = FileUtil.get().getBitmap(“你的url”);
    if (null != bitmap) {
    card.setBitmap(bitmap);
    bitmap = ImageUtil.get().reduce(bitmap, Constant.PHOTO_SIZE, Constant.PHOTO_SIZE, false);
    handler.sendMessage(new Message());
    }
    }
    }.start();
    }private Handler handler = new Handler() {
    public void handleMessage(Message msg) {
    ((ImageView) findView(R.id.imgPhoto)).setImageBitmap(bitmap);
    }
    };