×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Oct 2009
    Location
    Assam, India
    Posts
    93

    Problem in appending image to the form

    I am just doing a simple program to append an PNG image to a form, but it is not appending. I am unable to detect the problem. I am giving u the complete program. Please check it and tell me where the actual problem is. The form shows the exit command but not the image. And in the console it prints the string "Failed to load image...". I have kept the PNG image in the res folder.


    package testPackage;

    import java.io.IOException;

    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.ImageItem;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;

    public class TestClass extends MIDlet implements CommandListener{

    private Display display;

    private Form form = new Form("Test Application");

    private Command CMD_EXIT = new Command("Exit", Command.EXIT, 0);

    private Image image;

    public ImageItem imageItem;

    public TestClass() {
    try {
    image = Image.createImage("/click.png");
    } catch (IOException e) {
    System.out.println("Failed to load image...");
    }
    imageItem = new ImageItem("Image", image, ImageItem.LAYOUT_CENTER, null);

    form.addCommand(CMD_EXIT);
    form.append(imageItem);
    form.setCommandListener(this);
    }

    protected void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }

    protected void pauseApp() {

    }

    protected void startApp() throws MIDletStateChangeException {
    display = Display.getDisplay(this);
    display.setCurrent(form);
    //Thread t = new Thread(this);
    //t.start();
    }

    public void commandAction(Command c, Displayable d) {
    if (c == CMD_EXIT) {
    destroyApp(true);
    notifyDestroyed();
    }
    }

    // public void run() {
    // }
    }

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Problem in appending image to the form

    An IOException from Image.createImage() indicates one of:

    * The image file does not exist (it is missing, or it is in the wrong folder (in the JAR), or the name does not match precisely (some devices are case-sensitive, some are not))

    * There is not enough memory to load the image (the memory needed is much greater than the size of the PNG file)

    Most likely is the first option: it is simply not finding the file. Try "/res/click.png".

    Graham.

  3. #3
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Problem in appending image to the form

    also you might want to place that .append() piece of code in a try/catch as to see if any exceptions are thrown whilst doing the actual append...

  4. #4
    Regular Contributor
    Join Date
    Oct 2009
    Location
    Assam, India
    Posts
    93

    Re: Problem in appending image to the form

    I had tried by writing the append code within the try/catch block but it is not throwing any exception. But when I try to print the exception in the

    try {
    image = Image.createImage("/click.png");
    } catch (IOException e) {
    e.printStackTrace();
    }


    it throws the following exception.

    java.io.IOException
    at javax.microedition.lcdui.ImmutableImage.getImageFromStream(+15)
    at javax.microedition.lcdui.ImmutableImage.<init>(+20)
    at javax.microedition.lcdui.Image.createImage(+8)
    at testPackage.TestClass.<init>(+39)
    at java.lang.Class.runCustomCode(+0)
    at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
    at com.sun.midp.midlet.Scheduler.schedule(+52)
    at com.sun.midp.main.Main.runLocalClass(+28)
    at com.sun.midp.main.Main.main(+80)


    I had also tried by writing "/res/click.png" but still it throws the exception.

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Problem in appending image to the form

    Unpack your jar file to see if click.png exisit in the JAR file.
    If the file is in res folder you then you can read it directly like Image image = Image.createImage("/click.png");
    chcek the file name of png and its case.

    thanks,
    ~Amitabh

  6. #6
    Regular Contributor
    Join Date
    Oct 2009
    Location
    Assam, India
    Posts
    93

    Re: Problem in appending image to the form

    When I had created the JAR file, I have not found the image in the JAR file but the image is in the res folder of the project. Whether I have to add the image manually in the JAD or JAR file??

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Problem in appending image to the form

    Quote Originally Posted by dhiraj.deka View Post
    When I had created the JAR file, I have not found the image in the JAR file but the image is in the res folder of the project. Whether I have to add the image manually in the JAD or JAR file??
    So now you can identify the real issue, its with the building process of your JAR.
    Which IDE or tools are you using for it.

    For starters its always recommanded to start with Ktoolbar of Sun WTK, plaese move your project to it and do its packaging using it.

    thanks,
    Ekta

  8. #8
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Problem in appending image to the form

    nope just build (or first try clean&build) your project and if the Image is in the src directory it should be included within the JAR...

  9. #9
    Regular Contributor
    Join Date
    Oct 2009
    Location
    Assam, India
    Posts
    93

    Re: Problem in appending image to the form

    I have got the cause of the problem. The problem occurred due to my mistake only. I was developing it using the EclipseME. For keeping the image, I had created just a folder as res, but I should have created it as a source folder(res). That's why the IOException was throwing. I suspected it when I did not get the image when I unpacked the JAR file.

    Thanks guys for looking into my matter.

  10. #10
    Registered User
    Join Date
    Jul 2009
    Posts
    15

    Re: Problem in appending image to the form

    Quote Originally Posted by dhiraj.deka View Post
    I have got the cause of the problem. The problem occurred due to my mistake only. I was developing it using the EclipseME. For keeping the image, I had created just a folder as res, but I should have created it as a source folder(res). That's why the IOException was throwing. I suspected it when I did not get the image when I unpacked the JAR file.

    Thanks guys for looking into my matter.
    normally. You leave your images in Res folder. also I did that but sometime I left it in Source folder.it run well.

Similar Threads

  1. load image problem
    By Pmarcoen in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2009-08-23, 06:19
  2. Can't show immutable image in Form
    By tomvp in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2007-05-15, 09:41
  3. Add image to Dynamic Form ???
    By Shilpa13 in forum Symbian User Interface
    Replies: 0
    Last Post: 2006-05-04, 11:40
  4. Problem with image decoding using CImageDecoder::DataNewL
    By sebi_ichim in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2005-08-30, 05:06
  5. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58

Posting Permissions

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