我在 NetBeans 上运行我的项目,但无法成功运行 .jar 文件。1. 我正在使用 Java 类库开发我的项目,后来发现清单文件中存在一些问题。. 2. 然后为了解决上述问题,我创建了项目作为 JavaApplication 项目,现在清单看起来像这样
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_22-b22 (Sun Microsystems Inc.)
Class-Path:
Main-Class: gameloftbraker.GameLoftBraker
在终端上它抛出以下异常:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:204)
at gameloftbraker.Ball.<init>(Ball.java:26)
at gameloftbraker.Arena.gameInit(Arena.java:71)
at gameloftbraker.Arena.addNotify(Arena.java:67)
at java.awt.Container.addNotify(Container.java:2584)
at javax.swing.JComponent.addNotify(JComponent.java:4687)
at java.awt.Container.addNotify(Container.java:2584)
at javax.swing.JComponent.addNotify(JComponent.java:4687)
at java.awt.Container.addNotify(Container.java:2584)
at javax.swing.JComponent.addNotify(JComponent.java:4687)
at javax.swing.JRootPane.addNotify(JRootPane.java:754)
at java.awt.Container.addNotify(Container.java:2584)
at java.awt.Window.addNotify(Window.java:707)
提前感谢您的帮助。我希望我没有遗漏任何东西。代码没有问题,因为它构建并成功运行,如果需要代码,请告诉我。
Ball.java
////////////////
package gameloftbraker;
import javax.swing.ImageIcon;
public class Ball extends Graphc implements Commn {
protected String ball = "../images/ball.png"; //address to ball graphic
protected int xdir;
protected int ydir;
public Ball(){
xdir = 2;
ydir = -2;
ImageIcon img = new ImageIcon(this.getClass().getResource(ball));
image = img.getImage();
height = image.getHeight(null);
width = image.getWidth(null);
resetState();
}
// rest of the functions * it works perfectly as project but unable to run in .jar
}