Why ByteArrayOutputStream sometimes gives me null pointer exception?
问题 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