简体   繁体   English

在Java Web Start中运行JNLP时发生NullPointerException(jar用作stardardlone)

[英]NullPointerException when running JNLP in Java Web Start (jar works as stardardlone)

I wrote my first application and I sill can't fix one issue. 我写了我的第一个应用程序,但无法解决一个问题。 When running application using Eclipse - everything works ok. 使用Eclipse运行应用程序时-一切正常。 After export to runnable jar (using Export required libraries into generated JAR), when running jar in Windows - everything works ok. 导出到可运行的jar后(使用“将所需的库导出到生成的JAR”),在Windows中运行jar时,一切正常。

When I'm trying to run application using jnlp file and Java Web Start - it throws: 当我尝试使用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)

The point is that following code: 关键是下面的代码:

imgURL = MedicalOfficeView.class.getResource("/patientsListSmall.jpg");
patientsList.setIcon(new ImageIcon(imgURL));

throws NullPointerException. 抛出NullPointerException。

I have image folder in my project, added it to classpath and used the code above. 我的项目中有图片文件夹,将其添加到类路径并使用了上面的代码。 It works only in Eclipse and standardlone jar file. 它仅在Eclipse和standardlone jar文件中起作用。 I checked jar file and image exists in main jar folder. 我检查了jar文件,并且图像存在于主jar文件夹中。

This is my jnlp code: 这是我的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>

I also tried to use following code in my application: 我还尝试在应用程序中使用以下代码:

URL imgURL = Thread.currentThread().getContextClassLoader().getResource("patientsListSmall.jpg");
patientsList.setIcon(new ImageIcon(imgURL));

as well as this one: 以及这个:

URL imgURL = getClass().getClassLoader().getResource("patientsListSmall.jpg");
patientsList.setIcon(new ImageIcon(imgURL));

Effect is the same - works only in eclipse and standardlone jar file. 效果是相同的-仅在Eclipse和standardlone jar文件中有效。

您的签名jar清单文件中是否具有Trusted-Library属性?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM