title: sending image from one mobile to another via sms using j2me language
body: <p>i am programming a mobile application in j2me in which i need to send an image from one mobile to another via sms.
  the problem is being encountered at the receiving end.the image is not being decoded properly.it is throwing ioexception....i m posting the code here..plz help me. </p>
  
  <pre><code>import javax.microedition.midlet.*;
  import javax.microedition.lcdui.*;
  import javax.microedition.io.*;
  import javax.wireless.messaging.*;
  import java.io.IOException;
  import javax.microedition.lcdui.game.*;
  import java.lang.*;
  import java.io.*;
  
  public class receive_mms extends MIDlet implements CommandListener
   {
      Display disp;
      //TextBox txtbox;
      MessageConnection msgConn;  
      Message msg;
      Form frm=null;
      byte[] msgrev;
      byte[] data;
      //String msgrev;
      Image im=null;
      Image im1=null;
      ImageItem img=null;
      int i,j;
      ByteArrayInputStream bais = null;
      Command cmd_exit;
  
  
  public receive_mms(){
      disp=Display.getDisplay(this);
      frm=new Form("photo dikho");
      i=frm.getWidth();
      j=frm.getHeight();
      cmd_exit=new Command("exit",Command.EXIT,1);
      frm.addCommand(cmd_exit);
      frm.setCommandListener(this);
      disp.setCurrent(frm);
  
      Thread t1 = new Thread()
      {
          public void run()
          {recieve();}
      };
      t1.start();
  
  
      //txtbox=new TextBox("Recieve Text","",100,TextField.ANY);      
  
  }
  
  public void commandAction(Command c,Displayable d)
  {   
            if(c==cmd_exit)
         {  
             notifyDestroyed();          
         }
  }
  
  
  
  
  public void startApp(){/*
  disp.setCurrent(frm);
  
      Thread t1 = new Thread()
      {
          public void run()
          {recieve();}
      };
      t1.start();
  
  
      */
  }
  public void pauseApp(){}
  public void destroyApp(boolean unconditional){}
  
  public void recieve(){
      //while(true)
      //{
          String mSenderAddress="";
          try{
  
          msgConn = (MessageConnection) Connector.open("sms://:1234");
          System.out.println("11");
          msg = msgConn.receive();// start listening and stuck here until a msg is received
          System.out.println("12");
          mSenderAddress = msg.getAddress();// Get info from message, from where da msg is beign sent
          System.out.println("3");
          System.out.println("add"+ mSenderAddress);
          System.out.println("msg aya:" + msg);
      msgConn.close();
          }catch(Exception e){System.out.println(e);}
  
  
          if (msg instanceof BinaryMessage) {
          //try{
              msgrev = ((BinaryMessage)msg).getPayloadData(); 
              data=msgrev.toByteArray();
              String val= new String(data);   
              System.out.println("yahoo");
  
              System.out.println("yahoo1");
  
      System.out.println(val);
              create(data); 
  
  
          }
  
  }
  public void create(byte[] bs)
  {
      try
      {         
                 String str=bs.toString();
              /*
              StringBuffer d=new StringBuffer();
               bais=new ByteArrayInputStream(bs);
               DataInputStream ds=new DataInputStream(bais);
               int len=bs.length;
               System.out.println("len="+len);
               if(len!=0)
               {
                int ch=0;
                while((ch=ds.read())!=-1)
                {
                 d.append((char)ch);
                }
  
               }
          System.out.println(d);
          str=d.toString();
          */
          //str=bs.toString();
          InputStream is= this.getClass().getResourceAsStream(str);
          System.out.println("string is"+str);           
          im = (Image)Image.createImage(is);
          System.out.println("line");
          im1 = (Image)Image.createImage(im, 0, 0, i, j, Sprite.TRANS_NONE);
          img = new ImageItem("yeh photo snd hui", im1, Item.LAYOUT_CENTER, "kyu nhi dikh rhi", Item.BUTTON);
          frm.append(img);
  
  
  
      }
      catch (Exception e)
      {
          System.out.println(e);
      }
  
  }
  }
  </code></pre>