模拟器没问题 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);
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);
解决方案 »
- lichee linux vmware ubuntu error
- android : cant find 'test.apk' to install
- android如何用代码判断屏幕是亮还是暗了?急!请进来接分,谢谢
- RedioGroup动态添加RedioButton问题,急~~
- Android画布刷新问题。
- NDK下用C去调JAVA的类的成员函数,老是出现java.lang.NoSuchMethodError,为什么?
- android执行时候的错误
- 程序出现“很抱歉,XX已停止运行”
- Fragment中的onStart()方法里能调用onCreateView()方法吗
- 求助关于OKHTTP3的问题
- onTouchEvent和GestureListener
- 为什没有contains??
这里的bm是null吧。
你is都做了判断了, bm也做一次判断吧
所以NullPointerException
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.
return null;
}
如果是null,Bitmap当然可以为空。
If the input stream is null, or cannot be used to decode a bitmap, the function returns null如果is不为null,说明input stream 不能转码成bitmap 则返回null
http://www.cnblogs.com/ixyx/archive/2011/04/07/Bitmap_decode.html
具体不能解码的原因我也不确定,应该不是参见网址里说的版本问题,
InputStream is=conn.getInputStream();
bm=BitmapFactory.decodeStream(is);
这种写法貌似小图片没问题,图片一大就有问题,大图片要换成getbytes方式。