title: Android Read-Only File System Error
body: <p>Hi I have a gallery in my app which shows the image in an image view when you click on the thumbnail. I am setting up a Long Click Listener for an alert dialog that has 2 buttons one to set as wallpaper and one to share. I have the share intent and the get drawing cache somewhat working. It works in the emulator but not on my phone. I have used many of the examples on this site to get this going but its not working at all. it keeps force closing the app on my phone. any help is appreciated.</p>
  
  <pre><code>                                alertDialog.setButton2("Share",
                      new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int which) {
  
                              imgView.setDrawingCacheEnabled(true);
                              Bitmap b = imgView.getDrawingCache();
                              File sdCard = Environment.getExternalStorageDirectory();
                              File file = new File(sdCard.getAbsolutePath() + "image.jpg");
  
                              try {
                                  file.createNewFile();
                                  OutputStream fos = null;
                                  fos = new FileOutputStream(file);
                                  b.compress(CompressFormat.JPEG, 100, fos);
                                  fos.flush();
                                  fos.close();
                              } catch (FileNotFoundException e) {
  
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                              } catch (IOException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                              }
  
                              Log.d("Save Example", "Image saved.");
  
                              Intent shareIntent = new Intent(Intent.ACTION_SEND);
                              Uri phototUri = Uri.parse("file:///sdcard/image.jpg");
                              shareIntent.setData(phototUri);
                              shareIntent.setType("image/jpeg");
                              shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
                              startActivity(Intent.createChooser(shareIntent, "Share Via"));
                          }
  
                      });
  
              alertDialog.show();
              return true;
          }
      });
  </code></pre>
  
  <p>Update: it seems to be a problem with</p>
  
  <pre><code>b.compress(CompressFormat.JPEG, 95, fos);
  </code></pre>
  
  <p>it keeps saying null pointer. </p>
  
  <p>Turns out the null pointer is actually a read_only error..So its not actually writing the file i get a  ioexception read-only file system. Why is it doing this?</p>