×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    createImage SDK 3d Edition FP2 - unable to load a resource image file

    My application has a PNG image file in the Source Packages res folder and uses this code to load the image
    Code:
    im = Image.createImage( "/image.png");
    In 3rd Edition FP1 no problem - the image is loaded and can be drawn to the canvas. But in FP2 this call causes an exception java.io.IOException and variable im remains null. Any advice?

    Here is a full code dump
    Code:
    /*--------------------------------------------------
    * ImmutableImage.java
    *
    * Draw immutable image on a canvas
    *
    * Example from the book:     Core J2ME Technology
    * Copyright John W. Muchow   http://www.CoreJ2ME.com
    * You may use/modify for any non-commercial purpose
    *-------------------------------------------------*/  
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class ImmutableImage extends MIDlet 
    {
      private Display  display;     // The display
      private ImageCanvas canvas;   // Canvas 
        
      public ImmutableImage()   {
        display = Display.getDisplay(this);
        canvas  = new ImageCanvas(this);
      }
     
      protected void startApp()  {
        display.setCurrent( canvas );
      }
     
      protected void pauseApp()
      { }
    
      protected void destroyApp( boolean unconditional )
      { }
     
      public void exitMIDlet()
      {
        destroyApp(true);
        notifyDestroyed();
      }
    }
    
    /*--------------------------------------------------
    * Class ImageCanvas
    *
    * Draw immutable image
    *-------------------------------------------------*/
    class ImageCanvas extends Canvas implements CommandListener
    {
      private Command cmExit;  // Exit midlet
        
      private ImmutableImage midlet;
      private Image im = null;      // immutable image
     
      public ImageCanvas(ImmutableImage midlet  )
      {
        this.midlet = midlet;
        
        // Create exit command & listen for events
        cmExit = new Command("Exit", Command.EXIT, 1);
        addCommand(cmExit);
        setCommandListener(this);
    
      } 
    
      /*--------------------------------------------------
      * Draw immutable image 
      *-------------------------------------------------*/
      protected void paint(Graphics g)
      {
    
          try {
                // Create immutable image from embedded files
                im = Image.createImage( "/image.png" );
            }
            catch (java.io.IOException e)  {
        //#if S60Emulator
                    System.err.println("Unable to locate or read image.jpg file " + e);             
        //#endif
                im = null;
            }  
        
        
        // if the image loaded, we can draw to the canvas
        if (im != null) {
            g.setColor(0x000000); // black background
            g.fillRect(0, 0, getWidth(), getHeight());
    
            g.drawImage(im, 10, 10, Graphics.LEFT | Graphics.TOP);
            
        } else {
            Font f = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
            g.setFont(f);
                // use font height as a line height
            int lineHeight = f.getHeight();
            int line = 0;
    
            g.setColor(0xffffff); // white background
            g.fillRect(0, 0, getWidth(), getHeight());
    
            g.setColor(0xCC0000);   // Red
            g.drawString("Image contains null", 0, lineHeight * (line), Graphics.TOP | Graphics.LEFT);
        }
      }
     
      public void commandAction(Command c, Displayable d) {
        
        if (c == cmExit)
          midlet.exitMIDlet();
            
        repaint();
      } // end of command action
    }
    Last edited by nicholso; 2008-07-10 at 07:54. Reason: added code

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    Re: createImage SDK 3d Edition FP2 - unable to load a resource image file

    I found the solution: to load the image on both FP1 and FP2 the source package folder must be made explicit in the path String
    Code:
    im = Image.createImage( "/res/image.png");
    On FP1, for some reason it works without including the folder in the path

Similar Threads

  1. Replies: 1
    Last Post: 2008-05-01, 08:08
  2. When load some MMP file, SDK was not found by Carbide
    By huangkuan in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2007-01-18, 04:47
  3. Series 60 Concept Emulator (SDK Beta 0.2 Linux) not working
    By mattbee in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2003-06-10, 11:43
  4. nokia 7210 modem via IR doesn't work !
    By oussamaaiadi in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2003-03-06, 10:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×