当jar文件运行正常解压缩时,无法使用NullPointerException执行 [英] Jar file failing to execute with NullPointerException when it runs fine unpacked

查看:449
本文介绍了当jar文件运行正常解压缩时,无法使用NullPointerException执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新构建遗留应用程序并减少部署所需的步骤。
为此,我将所有类文件和资源打包到一个jar文件中。

I'm attempting to restructure a legacy application and reduce the steps needed to deploy. To do this, I'm packaging all the class files, and Resources into a jar file.

我正在使用此命令来包装所有内容:

I'm using this command to jar everything:


jar -cfm ../Deploy/JEmu.jar Manifest.txt * .class Resources /

jar -cfm ../Deploy/JEmu.jar Manifest.txt *.class Resources/

我的清单文件如下所示:

My manifest file looks like this:

Manifest-Version: 1.0  
Created-By: 1.2.2 (Sun Microsystems Inc.)  
Main-Class: JEmu  
Name: JEmu.class  

作为入口点的类是JEmu.class,它打包在jar中,但是当我运行jar时出现这个错误:

The class that is the entry point is JEmu.class, which is packaged in the jar, but when I run the jar I get this error:

java -jar JEmu.jar
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(Unknown Source)
        at ControlBar.<init>(ControlBar.java:88)
        at JEmu.<clinit>(JEmu.java:85)
Could not find the main class: JEmu. Program will exit.

我不确定是什么造成的。

I'm not exactly sure what is causing that.

ControlBar第88行是:

Line 88 of ControlBar is:

stopButton = new JButton( new ImageIcon( classLoader.getResource("Resources/stop.gif")));

我做错了什么,当它没有打包成罐子时一切正常?

What am I doing wrong, it all works when it's not packaged into a jar?

推荐答案

classLoader.getResource(Resources / stop.gif)可能找不到指定的资源。发生这种情况时,它返回 null ,因此 NullPointerException

classLoader.getResource("Resources/stop.gif") probably cannot find the specified resource. When this happens, it returns null, hence the NullPointerException.

这篇关于当jar文件运行正常解压缩时,无法使用NullPointerException执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆