Basic Image Display

Hi everybody.

I have been trawling through the posts trying to find something that could help me with my problem, but nothing quite sets it straight in my mind.

I am a complete newbie to this, hence the posting in this section…
would it be possible for someone to please help me output this image to the screen? its driving me insane :’(

Thanks in advance.

package phone;

import javax.microedition.midlet.;
import javax.microedition.lcdui.
;
import javax.microedition.lcdui.game.GameCanvas;
import java.io.*;

public class Midlet extends MIDlet {

 private Display display;
 Image pic = null;

public void startApp() {
    
    
    ImageItem image;
 
    
    try{
    pic = Image.createImage("pic.png");
    }
    catch(IOException e)
    {;}
    
}
     public void paint(Graphics g){ 
     g.drawImage(pic, 10, 10, Graphics.TOP|Graphics.LEFT);
     //g.drawRect(5,5,20,20);
    } 

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

}

If that were normal java I’d say “read the API docs for the Graphics.drawImage(…) method I think your args are wrong” but I have no experience with j2me.

Plus, you should never mask exceptions. Always print a stack trace, especially when developing. Maybe your problem is your image is not being loaded. If you print the stack trace, you will know for sure.

[quote]Plus, you should never mask exceptions. Always print a stack trace, especially when developing. Maybe your problem is your image is not being loaded. If you print the stack trace, you will know for sure.
[/quote]
Yeah - in pseudocode you have written:


1. If there are any mistakes, errors, or bugs in my code whilst doing this:
2. ...do something
3. then don't tell me about it. Pretend nothing went wrong. My code is always perfect and I never make any mistakes.

Of course, there are occasions where you believe you really can’t make a mistake, such as:


File f = new File( "blah" );
if( f.exists() )
{
  try{
     new FileInputStream( f );
     ...etc
   }
   catch( FileNotFoundException e )
   {
      //Um...this isn't possible. So do nothing.
   }
}

…although even there it actually is theoretically possible - the file could be deleted just a nanosecond after you checked if it existed :).