Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting a bitmap to file in the sdcard
    primarykey
    data
    text
    <p>I am trying to compress the bitmap into a jpg in my code. I get a nullpointer exception, Please advice</p> <pre><code>new Thread(new Runnable() { @Override public void run() { Cursor imageCursor=getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,new String[]{MediaStore.Video.Media.DATA},MediaStore.Video.Media.DISPLAY_NAME+"=?" ,new String[]{imageTitle},null); imageCursor.moveToFirst(); final String imageData=imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Video.Media.DATA)); dbConnection connection=new dbConnection(getApplicationContext()); SQLiteDatabase db=connection.getWritableDatabase(); File imageFile=new File(imageData); File outputFile=new File("mnt/sdcard/Images/hiddenImage.jpg"); InputStream is; try { is = new FileInputStream(imageFile); InputStreamReader inputreader=new InputStreamReader(is); BufferedReader buffReader=new BufferedReader(inputreader); final ByteArrayBuffer buffer=new ByteArrayBuffer(512); int i; while((i=buffReader.read())!=-1) { buffer.append(i); } Bitmap imagefile=BitmapFactory.decodeByteArray(buffer.toByteArray(), 0, buffer.toByteArray().length); OutputStream os=new FileOutputStream("mnt/sdcard/Images/testing.jpg"); imagefile.compress(Bitmap.CompressFormat.JPEG, 100, os); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }).start(); </code></pre> <p>Here is the stack trace:</p> <pre><code>07-09 14:57:48.595: ERROR/AndroidRuntime(5761): FATAL EXCEPTION: Thread-9 07-09 14:57:48.595: ERROR/AndroidRuntime(5761): java.lang.NullPointerException 07-09 14:57:48.595: ERROR/AndroidRuntime(5761): at com.messageHider.viewImageThumb$1$1.run(viewImageThumb.java:106) 07-09 14:57:48.595: ERROR/AndroidRuntime(5761): at java.lang.Thread.run(Thread.java:1096) </code></pre> <p>The exception is thrown where I am trying to compress the bitmap: //::imagefile.compress(Bitmap.CompressFormat.JPEG, 100, os);</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload