日期:2014-05-20  浏览次数:20698 次

我的程序打包后图片死活加载不进来,谁能帮我打包 50分
SSCanvas.java
=====================
Java code
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


public class SSCanvas extends Canvas{
    private Display display;
    private Image[] slides;
    private String[] captions = {"Love Circle Bowl","Double Wide Spine",
                                  "Flume Zoom Over-vert","Kulp De Sac Bowl","Louie's Ledge"};
    private int curSlide = 0;
    public SSCanvas(Display d)
    {
        super();
        display = d;
        
        try
        {
            slides = new Image[5];
            slides[0] = Image.createImage("/0.JPG");
            slides[1] = Image.createImage("/1.JPG");
            slides[2] = Image.createImage("/2.JPG");
            slides[3] = Image.createImage("/3.JPG");
            slides[4] = Image.createImage("/4.JPG");
        }
        catch (IOException e)
        {
            System.err.print("Failed loading images");
        }        
    }
    
    void start()
    {
        display.setCurrent(this);
        repaint();
    }
    
    public void keyPressed(int keyCode)
    {
        int action = getGameAction(keyCode);
        switch(action)
        {
            case LEFT:
                if(--curSlide < 0)
                    curSlide = slides.length - 1;
                repaint();
                break;
            case RIGHT:
                if(++curSlide >= slides.length)
                    curSlide = 0;
                repaint();
                break;
        }
    }
    
    public void paint(Graphics g)
    {
        g.setColor(255,255,255); // 白色
        g.fillRect(0, 0, getWidth(), getHeight());
        
        g.drawImage(slides[curSlide], getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);
        
        Font f = Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM);
        g.setFont(f);
        
        g.setColor(0,0,0); // 黑色
        g.drawString(captions[curSlide], getWidth()/2, 0, Graphics.TOP | Graphics.HCENTER);
    }
}



SlideshowMIDlet
==================
Java code
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;


public class SlideshowMIDlet extends MIDlet implements CommandListener {
private SSCanvas canvas;
    
    public void startApp()
    {
        if (canvas == null)
        {
            canvas = new SSCanvas(Display.getDisplay(this));
            Command exitCommand = new Command("Exit", Command.EXIT, 0);
            canvas.addCommand(exitCommand);
            canvas.setCommandListener(this);
        }
        
        canvas.start();
    }
    
    public void pauseApp()
    {}
    
    public void destroyApp(boolean uncoditional)
    {}

    public void commandAction(Command c, Displayable s) {
        if (c.getCommandType() == Command.EXIT)
        {
            destroyApp(true);
            notifyDestroyed();
        }        
    }
}




在eclipse里调试运行都没问题,打包后图片读取异常,谁能帮我打包看看怎么回事

分不够嚷嚷,我在加

------解决方案--------------------
slides[0] = Image.createImage("/0.JPG");

改成
slides[0] = Image.createImage("0.JPG");

然后打包
确认 0.JPG 在jar的根目录下面

------解决方案--------------------
确认 0.JPG 在jar的根目录下面