Why ByteArrayOutputStream sometimes gives me null pointer exception?

旧时模样 提交于 2020-01-05 05:11:07

问题


When loading a picture into byte[] in smartphone app sometimes ByteArrayOutputStream gives me nullpointerexception any explanation?

Bitmap bm = BitmapFactory.decodeFile(path);
System.out.println("BITMAP: "+bm != null);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 100, buffer);

回答1:


Are you sure it's ByteArrayOutputStream that's giving you the NullPointerException?

Or is it happening at bm.compress? bm can be null - likely due to you passing in an invalid path.




回答2:


The problem wasn't the code it was the thread that entered there first.



来源:https://stackoverflow.com/questions/20577373/why-bytearrayoutputstream-sometimes-gives-me-null-pointer-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!