3 Replies - 1711 Views - Last Post: 03 November 2011 - 02:12 AM

#1 T_A_R  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 10

Image loading problem

Posted 22 July 2011 - 06:22 AM

I am trying to add a image to Form but there is an exception.My code is given below.
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class ImageFind extends MIDlet
{
    Display display;
    Form form;

    public ImageFind()
    {
        display=Display.getDisplay(this);
        form=new Form("Image");

        try
        {
            ImageItem itemIm=new ImageItem("Copyright: ",Image.createImage("G://JAVA//J2ME//J2ME Code//ImageLoad//src//image//exit2.png"),ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER,"Right");
            form.append(itemIm);
        } catch (Exception e)
        {
            form.append(new StringItem("Copyright","Image not Found "+e));
        }
    }


    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    protected void pauseApp() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    protected void startApp() throws MIDletStateChangeException
    {
        display.setCurrent(form);
    }

}




Is This A Good Question/Topic? 0
  • +

Replies To: Image loading problem

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10562
  • View blog
  • Posts: 39,087
  • Joined: 27-December 08

Re: Image loading problem

Posted 22 July 2011 - 06:23 AM

Post the stack trace.
Was This Post Helpful? 0
  • +
  • -

#3 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: Image loading problem

Posted 22 July 2011 - 07:29 AM

Hmmm:
ImageItem itemIm=new ImageItem("Copyright: ",Image.createImage("G://JAVA//J2ME//J2ME Code//ImageLoad//src//image//exit2.png"),ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER,"Right");
You here got full path to your image, but it's wrong. Try to do it:
ImageItem itemIm=new ImageItem("Copyright: ",Image.createImage("//image//exit2.png"),ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER,"Right");

Was This Post Helpful? 0
  • +
  • -

#4 tauit_dnmd  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 129
  • Joined: 25-March 10

Re: Image loading problem

Posted 03 November 2011 - 02:12 AM

ImageItem itemIm=new ImageItem("Copyright: ",Image.createImage("G://JAVA//J2ME//J2ME Code//ImageLoad//src//image//exit2.png"),ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_NEWLINE_AFTER,"Right");




-> We run J2ME app in a emulater , it 's not on computer --> so, Emulater can't know your image path.

So you must add image to J2ME project , and use relative path to load image to Form in j2me.
Such as: "/images/img1.jpg" .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1