【发布时间】:2013-11-26 01:14:34
【问题描述】:
我无法让我的 jar 文件运行,所以我在 cmd 中执行了“java -Xmx1024m -jar test.jar”,但出现了很多错误。
我在路径中设置了图像资源和 jar 库。不过,它在 Eclipse 中运行良好。任何帮助都会很棒。谢谢。
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 和床单的地方
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
);
}
}
}
【问题讨论】:
-
您可以粘贴错误而不是屏幕转储,以便我们自己复制粘贴并帮助您吗?一些代码也会很有帮助——尤其是第 117 行附近的 FinalRevNoise.java。
-
@hexafraction 在第 117 行添加了代码。但不确定如何在 cmd 中复制。
-
@SolidCloudinc 右键单击,选择标记,选择您的文本,然后按 Enter。
-
@hichris123 谢谢,已更新
-
好吧,你在第 117 行有一个空指针。假设列表是准确的,可能是“sprites”,也可能是“bigImg”。
标签: java eclipse jar compilation cmd