0

I am try to load image on Canvas but it giving java.io.IOException exception. I don't know in which folder i have to put image. but right now i am putting image in F:\New Folder\DrawImage\src\Waterfall.png. i am using netbean editor for coding. reference code from here

public class Midlet extends MIDlet {

public Display display;

public void startApp() {

    Canvas obj = new DrawImage();

    display = Display.getDisplay(this);
    display.setCurrent(obj);

}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public class DrawImage extends Canvas{

    int width = getWidth();
    int height = getHeight();

    protected void paint(Graphics g) {
        try {

            System.out.println("111111");
            Image image = Image.createImage("/Waterfall.png");
            if(image != null)
                g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
            else
                System.out.println("2222");
        } catch (IOException ex) {
            System.out.println(ex);
        }   
    }  
}

}

Pawan Chaurasiya
  • 881
  • 2
  • 16
  • 30
  • Image image = Image.createImage("Waterfall.png"); - remove "/" OR you can create res folder in your project, add it into Resource, and call Image.createImage("/Waterfall.png"); – Thanh Le Mar 14 '14 at 08:48
  • `Image.createImage(filename)` only loads files from within your JAR file (which is probably also what you want). If you want to load from SD card, then you should use FileConnection API, but I don't think that's what you want. Try placing your `Waterfall.png` file either in the root directory of your source, or else in a folder with the name `res`. – mr_lou Mar 15 '14 at 06:31

1 Answers1

0

you need to make new folder at project folder and rename as rsc and copy and paste image in this folder. after that you need to go project properties and click on Build -> Libraries and Resources on that window you find Add Folder button click on that button locate you rsc folder and click ok. then run your project.

Pawan Chaurasiya
  • 881
  • 2
  • 16
  • 30