当app作为Java Web Start运行时,为什么Desktop API会抛出NPE?

时间:2014-07-03 16:44:44

标签: java maven javafx desktop java-web-start

我只使用Java大约6个月,所以我绝对是新手。此外,我几天前在Oracle技术网络社区发布了这个问题,但没有听到任何消息。

我一直在开发的应用程序目前正在通过Web启动进行beta测试。我们认为这是让用户及时了解最新错误修复的最佳方法。我想我应该提到它是一个使用Maven的JavaFX应用程序。在应用程序中,我使用了Desktop API的OPEN和MAIL操作。 OPEN操作用于打开系统文件夹浏览器。这是我需要开展工作的行动。 MAIL操作更方便用户使用。从可执行jar运行应用程序时,两者都可以正常工作,但是当通过Web启动应用程序启动时,我得到两者的NPE。它通过了isDesktopSupported测试。所有内容都使用经过验证的DigiCert证书进行签名,并设置了所有权限。当应用程序首次启动时,它会在用户主目录中创建一个文件夹和配置文件,没有任何问题。

我创建了一个小型演示应用,以确保我的应用中的其他地方没有导致问题,但我得到完全相同的错误。我发布的代码来自演示应用程序。

FXMLController.java

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;

public class FXMLController implements Initializable {

    @FXML
    private Button button;
    @FXML
    private Hyperlink hyperlink;

    @FXML
    private void handleButtonAction(ActionEvent event) {
    if (Desktop.isDesktopSupported()) {
        if (Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { //NPE thrown here
        try {
            Desktop.getDesktop().open(new File(System.getProperty("user.home")));
        } catch (IOException ex) {
            Logger.getLogger(FXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }
        } else {
        System.out.println("The OPEN action is not supported on your current platform.");
        }
    } else {
        System.out.println("The Desktop class is not supported on your current platform.");
    }
    }

    @FXML
    private void handleLinkAction(ActionEvent event) {
    if (Desktop.isDesktopSupported()) {
        if (Desktop.getDesktop().isSupported(Desktop.Action.MAIL)) { //NPE thrown here
        try {
            Desktop.getDesktop().mail(new URI("mailto:email@testing.yes"));
        } catch (IOException | URISyntaxException ex) {
            Logger.getLogger(FXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }
        } else {
        System.out.println("The MAIL action is not supported on your current platform.");
        }
    } else {
        System.out.println("The Desktop class is not supported on your current platform.");
    }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    }
}

JNLP文件

<?xml version="1.0" encoding="UTF-8"?>  
<jnlp spec="1.0+" xmlns:jfx="http://javafx.com" href="DesktopClassTesting.jnlp">  
    <information>  
  <title>DesktopClassTesting</title>  
  <vendor>USGS</vendor>  
    </information>  
    <security>  
  <all-permissions/>  
    </security>  
    <update check="always" policy="always" />  
    <resources>  
  <j2se version="1.7.0_60+" href="http://java.sun.com/products/autodl/j2se" />  
  <jar href="DesktopClassTesting.jar" main="true" version="0.1-SNAPSHOT"/>  
  <property name="jnlp.versionEnabled" value="true"/>  
    </resources>  
    <application-desc name="Desktop Class Testing"/>  
    <jfx:javafx-desc main-class="gov.usgs.tnm.desktopclasstesting.MainApp" name="MainApp"/>  
</jnlp>  

OPEN动作堆栈跟踪

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException  
  at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)  
  at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)  
  at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)  
  at javafx.event.Event.fireEvent(Unknown Source)  
  at javafx.scene.Node.fireEvent(Unknown Source)  
  at javafx.scene.control.Button.fire(Unknown Source)  
  at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)  
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)  
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)  
  at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)  
  at javafx.event.Event.fireEvent(Unknown Source)  
  at javafx.scene.Scene$MouseHandler.process(Unknown Source)  
  at javafx.scene.Scene$MouseHandler.access$1800(Unknown Source)  
  at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)  
  at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)  
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)  
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)  
  at java.security.AccessController.doPrivileged(Native Method)  
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)  
  at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)  
  at com.sun.glass.ui.View.notifyMouse(Unknown Source)  
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)  
  at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)  
  at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)  
  at java.lang.Thread.run(Unknown Source)  
Caused by: java.lang.reflect.InvocationTargetException  
  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 sun.reflect.misc.Trampoline.invoke(Unknown Source)  
  at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)  
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
  at java.lang.reflect.Method.invoke(Unknown Source)  
  at sun.reflect.misc.MethodUtil.invoke(Unknown Source)  
  ... 48 more  
Caused by: java.lang.NullPointerException  
  at java.awt.Desktop.getDesktop(Unknown Source)  
  at gov.usgs.tnm.desktopclasstesting.FXMLController.handleButtonAction(FXMLController.java:30)  
  ... 57 more  

MAIL action stacktrace

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException  
  at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)  
  at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)  
  at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)  
  at javafx.event.Event.fireEvent(Unknown Source)  
  at javafx.scene.Node.fireEvent(Unknown Source)  
  at javafx.scene.control.Hyperlink.fire(Unknown Source)  
  at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)  
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)  
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)  
  at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)  
  at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)  
  at javafx.event.Event.fireEvent(Unknown Source)  
  at javafx.scene.Scene$MouseHandler.process(Unknown Source)  
  at javafx.scene.Scene$MouseHandler.access$1800(Unknown Source)  
  at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)  
  at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)  
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)  
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)  
  at java.security.AccessController.doPrivileged(Native Method)  
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)  
  at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)  
  at com.sun.glass.ui.View.notifyMouse(Unknown Source)  
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)  
  at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)  
  at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)  
  at java.lang.Thread.run(Unknown Source)  
Caused by: java.lang.reflect.InvocationTargetException  
  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 sun.reflect.misc.Trampoline.invoke(Unknown Source)  
  at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)  
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
  at java.lang.reflect.Method.invoke(Unknown Source)  
  at sun.reflect.misc.MethodUtil.invoke(Unknown Source)  
  ... 48 more  
Caused by: java.lang.NullPointerException  
  at java.awt.Desktop.getDesktop(Unknown Source)  
  at gov.usgs.tnm.desktopclasstesting.FXMLController.handleLinkAction(FXMLController.java:51)  
  ... 57 more  

如果需要,我可以发布FXML文件和MainApp.java。我已经在这方面工作了一段时间没有成功,所以任何见解都会很棒。感谢。

1 个答案:

答案 0 :(得分:0)

事实证明这是一个已知的错误,在最近发布的Java 7_65和Java 8_11中得到了纠正。这是数据库中错误描述的链接。

http://bugs.java.com/view_bug.do?bug_id=8019274