Jar文件不会运行。在cmd中获取错误

时间:2013-11-26 01:14:34

标签: java eclipse jar compilation cmd

我无法运行我的jar文件所以我在cmd中执行了“java -Xmx1024m -jar test.jar”,我收到了很多错误。

我在路径中设置了图像资源和jar库。虽然它在日食中工作正常。任何帮助都会很棒。感谢。

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at ImagePanel.<init>(FinalRevNoise.java:117)
        at FinalRevNoise.createAndShowGUI(FinalRevNoise.java:53)
        at FinalRevNoise.access$0(FinalRevNoise.java:48)
        at FinalRevNoise$1.run(FinalRevNoise.java:42)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$200(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

这是我定义spries和sheet

的地方
BufferedImage bigImg; //sprite sheets
BufferedImage bigImg2;
BufferedImage bigImg3;

BufferedImage[] sprites; //individual sprites
BufferedImage[] sprites2;
BufferedImage[] sprites3; 

代码大约117

public ImagePanel(){
         try {

             bigImg = ImageIO.read(new File("res/sheet.png")); //sprite sheet paths
             bigImg2 = ImageIO.read(new File("res/sheet2.png"));
             bigImg3 = ImageIO.read(new File("res/sheet3.png"));


         } catch (IOException e) {
         }

         final int width = 20; //sprite width/height = 20 pixels
         final int height = 20;
         final int rows = 6; // 6 rows and 5 collums
         final int cols = 5;
         sprites = new BufferedImage[rows * cols]; //sets up the sprite arrays
         sprites2 = new BufferedImage[rows * cols];
         sprites3 = new BufferedImage[rows * cols];

         for (int i = 0; i < rows; i++) //goes through sprite sheet and puts sprites into an array
         {
             for (int j = 0; j < cols; j++)
             {
                 sprites[(i * cols) + j] = bigImg.getSubimage( //this is line 117
                     j * width,
                     i * height,
                     width,
                     height
                 );
             }
         }
}

2 个答案:

答案 0 :(得分:1)

第117行:

sprites[(i * cols) + j] = bigImg.getSubimage(

由于此处出现NullPointerException,因此sprite为null,或bigImg为null。 sprite不能为null,因为您只需将其设置为新数组。因此bigImg为空。

为什么bigImg为null?因为

ImageIO.read(new File("res/sheet.png"))

抛出IOException。

答案 1 :(得分:0)

您能否告诉我们jar文件与 res 文件夹的关系在哪里?

第117行的NullPointerException返回到行

bigImg = ImageIO.read(new File("res/sheet.png")); 

您的jar文件很可能不在同一项目文件夹中,该文件夹包含 src {{1} } 文件夹。如果你把jar文件放在那里,res将不会为空。