模拟器没问题 motoME722真机测试 bm.compress(Bitmap.CompressFormat.PNG, 100, os);报NullPointerException
log日志是以warn的形式报的。
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
is = conn.getInputStream();
if(is==null){
return null;
}
Bitmap bm = BitmapFactory.decodeStream(is);
os = new ByteArrayOutputStream();  
bm.compress(Bitmap.CompressFormat.PNG, 100, os);

解决方案 »

  1.   

    Bitmap bm = BitmapFactory.decodeStream(is);
    这里的bm是null吧。
    你is都做了判断了, bm也做一次判断吧
      

  2.   

    判断bm为null 这是为啥 is不为null  bm可能是啥原因导致为null的 求解??
      

  3.   

    如果bm为NULL   则compress(Bitmap.CompressFormat.PNG, 100, os)这个方法是哪里呢,谁调用呢?
    所以NullPointerException
      

  4.   

    我现在明白NullPointerException的原因,我不明白的是Bitmap bm = BitmapFactory.decodeStream(is);这里,BitmapFactory.decodeStream(is)为啥返回的是null, is经过判断是非空的。
      

  5.   

    因为InputStream不一定能构造成bm;
      

  6.   

    public static Bitmap decodeStream (InputStream is)
    Since: API Level 1Decode an input stream into a bitmap. If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.
    Parameters
    is  The input stream that holds the raw data to be decoded into a bitmap.
    Returns    The decoded bitmap, or null if the image data could not be decoded. 
      

  7.   

    if(is==null){
        return null;
    }
    如果是null,Bitmap当然可以为空。
      

  8.   

    你的Bitmap 为空了 你判断一下把楼主~~~~~~
      

  9.   


    If the input stream is null, or cannot be used to decode a bitmap, the function returns null如果is不为null,说明input stream 不能转码成bitmap  则返回null
      

  10.   

    应该是你的url地址有问题,你的url地址连接到的资源不能解析成图片。所以是null
      

  11.   

    你的is不为空,但是你创建bitmap的时那个工厂可能没有构造出来bitmap,bitmap就null了
      

  12.   

    问题解决了,一直没有结贴,确实是因为is不能构成bitmap,不过不是图片的问题,具体可以参见
    http://www.cnblogs.com/ixyx/archive/2011/04/07/Bitmap_decode.html
    具体不能解码的原因我也不确定,应该不是参见网址里说的版本问题,
    InputStream is=conn.getInputStream();
    bm=BitmapFactory.decodeStream(is);     
    这种写法貌似小图片没问题,图片一大就有问题,大图片要换成getbytes方式。