title: How to fix a java.io.NotSerializableException: android.graphics.Bitmap
body: <p>Hello im trying to save a image location on sreen to internal storage but I get a NotSerializableException.I went searching and found that the problem is that Bitmap is not designed  to be serialized at this link  <a href="https://stackoverflow.com/questions/4880583/problem-serializing-drawable">Problem serializing Drawable</a> I never really understood how he fix the problem throw the example. if someone could explain how he fix his NotSerializableException and help me get  with mine it would be greatly appreciated</p>
  
  <hr>
  
  <p>Here is my Elememt Class</p>
  
  <pre><code>public class Element extends main implements Serializable{
  private int mX;
  private int mY;
  int location2 ;
  Matrix elementlocation;
  private Bitmap mBitmap;
  Canvas canvas2;
  
  public Element(Resources res, int x, int y) {
    location2 =item3;
      mBitmap = BitmapFactory.decodeResource(res, location2);
      mX = x - mBitmap.getWidth() / 2;
      mY = y - mBitmap.getHeight() / 2;
    }
  
  public Element(){
  
  }
  public void doDraw2(Canvas canvas) {
      elementlocation=new Matrix();
      elementlocation.postTranslate(mX,mY);
      canvas2=canvas;
      canvas2.drawBitmap(mBitmap, elementlocation,null);
      }
  public void setelementlocation(float num1,float num2){
     elementlocation=new Matrix();
     elementlocation.postTranslate(num1,num2);
   }
   public Canvas getCanvas2(){
      return(canvas2);
   }
  public String toString() {
      String sentence;
      sentence= mBitmap+" "+mX+" "+mY;
      return (sentence);
   }
  
   }
  </code></pre>
  
  <hr>
  
  <p>Here is my onTouch method in my Panel class</p>
  
  <pre><code>public boolean onTouchEvent(MotionEvent event) {
     mainactivity=new main();
      Log.v("test", "you have touched the sreen: ");      
  
   mElements.add(new Element(getResources(),(int) event.getX(),(int) event.get()));       
   mainactivity.writeElement(new Element(getResources(),(int) event.getX(),(int) event.getY()),this.getContext());
          Log.v("Gesture", "is 1 ");   
          return super.onTouchEvent(event);
  }
  </code></pre>
  
  <hr>
  
  <p>Here is my write element method in my main class</p>
  
  <pre><code>  public void writeElement(Element obj, Context context){
      Log.v("main", "made it to method writeElement" );
      File f = new File(context.getFilesDir(),FILENAME);
      try {
  fos = new FileOutputStream(f);
      ObjectOutputStream objectwrite = new ObjectOutputStream(fos);
      objectwrite.writeObject(obj);
   fos.close(); 
   Log.v("main", "file was  made File ");
  
   }catch (FileNotFoundException e){
      e.printStackTrace();
      Log.v("main", "file was not made File not found ");
   } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      Log.v("main", "file was not made File IOException ");
  }
   }
  </code></pre>
  
  <hr>
  
  <p>Update</p>
  
  <pre><code>public Element(Resources res, int x, int y) {
      location2 =item3;
      ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
      mBitmap = BitmapFactory.decodeResource(res, location2);
      mX = x - mBitmap.getWidth() / 2;
      mY = y - mBitmap.getHeight() / 2;
      mBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); 
  
  
  }
  </code></pre>