title: Writing a bitmap to file in the sdcard
body: <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>