问题
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