[英]NullPointerException when running JNLP in Java Web Start (jar works as stardardlone)
我写了我的第一个应用程序,但无法解决一个问题。 使用Eclipse运行应用程序时-一切正常。 导出到可运行的jar后(使用“将所需的库导出到生成的JAR”),在Windows中运行jar时,一切正常。
当我尝试使用jnlp文件和Java Web Start运行应用程序时-抛出:
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at MedicalOffice.MedicalOfficeView.<init>(MedicalOfficeView.java:122)
关键是下面的代码:
imgURL = MedicalOfficeView.class.getResource("/patientsListSmall.jpg");
patientsList.setIcon(new ImageIcon(imgURL));
抛出NullPointerException。
我的项目中有图片文件夹,将其添加到类路径并使用了上面的代码。 它仅在Eclipse和standardlone jar文件中起作用。 我检查了jar文件,并且图像存在于主jar文件夹中。
这是我的jnlp代码:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0" codbase="http://localhost:8081/MOS/"
href="MedicalOfficeSoftware.jnlp">
<information>
<title>Small Medical Office Management Software</title>
<vendor>Pawel Raczy</vendor>
<description>MedicalOfficeManagement</description>
<offline-allowed/>
</information>
<resources>
<j2se version="1.8+"/>
<jar href="MedicalOfficeSoftware.jar"/>
</resources>
<application-desc main-class="MedicalOffice.MVCMedicalOffice"/>
</jnlp>
我还尝试在应用程序中使用以下代码:
URL imgURL = Thread.currentThread().getContextClassLoader().getResource("patientsListSmall.jpg");
patientsList.setIcon(new ImageIcon(imgURL));
以及这个:
URL imgURL = getClass().getClassLoader().getResource("patientsListSmall.jpg");
patientsList.setIcon(new ImageIcon(imgURL));
效果是相同的-仅在Eclipse和standardlone jar文件中有效。
您的签名jar清单文件中是否具有Trusted-Library属性?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.