請原諒我的Java Webstart的瞭解有限,因爲我很新到這一點。顯示圖像
所以我得到了我的應用程序在我的電腦上的JAR文件的工作,在一個靜態方法使用這段代碼(類擴展JFrame的):
ImageIcon image = new javax.swing.ImageIcon(window.getClass().getResource("/resources/img/loginWindowTop.jpg"));
//ImageIcon image = new ImageIcon(window.getClass().getResource("/resources/img/loginWindowTop.jpg")); // tried this too
JLabel imageLabel = new JLabel(image);
imageLabel.setBounds(rect);
window.add(imageLabel);
我的電腦上直接從啓動應用程序時,它的工作原理JAR文件。當從JNLP文件的Web服務器測試,應用程序崩潰顯示此:
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at gui.LoginWindow.create(LoginWindow.java:42)
at main.Starter.main(Starter.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我會很感激,如果有人可以解釋做什麼。我在互聯網上搜索了很長時間,沒有解決方案可以幫助我(還)。我希望這不是因爲我正在使用靜態JFrame(在我的代碼段中稱爲窗口)?
看來'loginWindowTop.jpg'不是在一個罐子裏那是JWS應用程序的運行時類路徑上。它包含哪些罐子? JNLP的內容是什麼? – 2012-04-21 15:31:18
僅供參考,以下是一個可用的示例(https://sites.google.com/site/drjohnbmatthews/googleolympiad)。 – trashgod 2012-04-21 16:13:30
當我在計算機或另一臺計算機上測試JAR時,它必須位於jar中,因爲它工作正常!我猜這個路徑在使用webstart時有點不同。 - 感謝這個例子,我會努力通過! – andreas 2012-04-21 17:19:20