문제

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