当应用程序作为Java Web Start运行时,为什么桌面API会抛出NPE?

jww-ME03

我使用Java大约只有6个月的时间,所以我绝对是新手。另外,几天前我确实在Oracle技术网络社区上发布了此问题,但没有听到任何声音。

我正在开发的应用程序目前正在通过网络启动进行Beta测试。我们认为这是使用户了解最新错误修复的最佳方法。我想我应该提到这是一个使用Maven的JavaFX应用程序。在应用程序中,我正在使用Desktop API的OPEN和MAIL操作。OPEN操作用于打开系统文件夹浏览器。这是我需要采取的行动。MAIL操作更多是为了用户方便。从可执行jar运行应用程序时,两者都工作正常,但是当通过Web Start启动应用程序时,两者都得到了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 protected]"));
        } 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  

邮件操作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。我已经为此工作了几天,但都没有成功,因此任何见解都会很棒。谢谢。

jww-ME03

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Web应用程序作为桌面应用程序

来自分类Dev

当应用程序后台运行时,将通知从Web服务器拉到iOS设备

来自分类Dev

当应用程序可以作为系统服务运行时,为什么要使用nohup?

来自分类Dev

当应用程序作为服务运行时,AcceptSecurityContext失败

来自分类Dev

是否可以在命令行中运行 Java 应用程序/作为 Web 服务

来自分类Dev

作为 Web 应用程序项目运行时的 404 页面

来自分类Dev

作为 Chrome 应用程序运行时如何使 Web 蓝牙配对按钮工作

来自分类Dev

在Azure上将jar作为Web应用程序运行

来自分类Dev

使用 API Gateway 作为 Web 应用程序的反向代理

来自分类Dev

如何将Windows应用程序作为Web应用程序运行

来自分类Dev

Web应用程序:在运行时删除文件

来自分类Dev

为什么以下golang程序会抛出运行时内存不足错误?

来自分类Dev

将Java应用程序(使用Spring的Web和桌面应用程序)与mongodb连接

来自分类Dev

当应用程序在后台运行时,Android传感器会监听

来自分类Dev

当应用程序在后台运行时,Admob是否会执行请求?

来自分类Dev

使用.NET Core Web API作为ASP.NET Web窗体应用程序的子路由

来自分类Dev

使用Jemmy测试Java Web Start应用程序

来自分类Dev

用Java Web Start应用程序替换JavaApplet

来自分类Dev

部署示例Java Web Start应用程序失败。

来自分类Dev

如何查看或启动Java Web Start应用程序?

来自分类Dev

为了使我能够从VS 2019在Azure上运行一个简单的Bottle Web应用程序,应将资源组和运行时堆栈设置为什么?

来自分类Dev

与Java Web应用程序相比,Java Web Start有什么优势?

来自分类Dev

当Web应用程序在Amazon Web Services上运行时查看控制台输出

来自分类Dev

使用 Spring Boot Thymeleaf 不要作为 Web 应用程序运行

来自分类Dev

将 Hazelcast 与运行在以 MongoDB 作为后端的 tomcat 上的 Web 应用程序集成

来自分类Dev

iOS Web应用程序作为本机应用程序

来自分类Dev

使用CSV作为Web应用程序的数据库有什么问题吗?

来自分类Dev

使用CSV作为Web应用程序的数据库有什么问题吗?

来自分类Dev

作为Web应用程序运行的Google Appscript是否有助于总触发器运行时配额?

Related 相关文章

  1. 1

    Web应用程序作为桌面应用程序

  2. 2

    当应用程序后台运行时,将通知从Web服务器拉到iOS设备

  3. 3

    当应用程序可以作为系统服务运行时,为什么要使用nohup?

  4. 4

    当应用程序作为服务运行时,AcceptSecurityContext失败

  5. 5

    是否可以在命令行中运行 Java 应用程序/作为 Web 服务

  6. 6

    作为 Web 应用程序项目运行时的 404 页面

  7. 7

    作为 Chrome 应用程序运行时如何使 Web 蓝牙配对按钮工作

  8. 8

    在Azure上将jar作为Web应用程序运行

  9. 9

    使用 API Gateway 作为 Web 应用程序的反向代理

  10. 10

    如何将Windows应用程序作为Web应用程序运行

  11. 11

    Web应用程序:在运行时删除文件

  12. 12

    为什么以下golang程序会抛出运行时内存不足错误?

  13. 13

    将Java应用程序(使用Spring的Web和桌面应用程序)与mongodb连接

  14. 14

    当应用程序在后台运行时,Android传感器会监听

  15. 15

    当应用程序在后台运行时,Admob是否会执行请求?

  16. 16

    使用.NET Core Web API作为ASP.NET Web窗体应用程序的子路由

  17. 17

    使用Jemmy测试Java Web Start应用程序

  18. 18

    用Java Web Start应用程序替换JavaApplet

  19. 19

    部署示例Java Web Start应用程序失败。

  20. 20

    如何查看或启动Java Web Start应用程序?

  21. 21

    为了使我能够从VS 2019在Azure上运行一个简单的Bottle Web应用程序,应将资源组和运行时堆栈设置为什么?

  22. 22

    与Java Web应用程序相比,Java Web Start有什么优势?

  23. 23

    当Web应用程序在Amazon Web Services上运行时查看控制台输出

  24. 24

    使用 Spring Boot Thymeleaf 不要作为 Web 应用程序运行

  25. 25

    将 Hazelcast 与运行在以 MongoDB 作为后端的 tomcat 上的 Web 应用程序集成

  26. 26

    iOS Web应用程序作为本机应用程序

  27. 27

    使用CSV作为Web应用程序的数据库有什么问题吗?

  28. 28

    使用CSV作为Web应用程序的数据库有什么问题吗?

  29. 29

    作为Web应用程序运行的Google Appscript是否有助于总触发器运行时配额?

热门标签

归档