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);
        }   
    }  
}

}

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top