JavaFX桌面应用程序无法在特定计算机上启动(在其他计算机上运行)

时间:2018-02-16 13:18:43

标签: javafx jfoenix

我有一个使用Swing的java桌面应用程序,我使用SceneBuilder在JavaFX中重新编写。

Swing应用程序适用于所有用户计算机(35计算机)。在JavaFX中重写应用程序后,在一台特定的计算机上,应用程序将无法启动并提供以下错误消息。

我无法弄清楚这个问题。如果有人能提供任何帮助,我感激不尽。 谢谢。

Exception in Application start method
java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/PaintConverter
        at com.jfoenix.controls.JFXPasswordField$StyleableProperties.<clinit>(JFXPasswordField.java:205)
        at com.jfoenix.controls.JFXPasswordField.<init>(JFXPasswordField.java:156)
        at idehmis.controller.LoginController.<init>(LoginController.java:51)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.base/java.lang.Class.newInstance(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml/javafx.fxml.FXMLLoader.load(Unknown Source)
        at idehmis.IDEHMIS.start(IDEHMIS.java:30)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        ... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.converters.PaintConverter
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

2 个答案:

答案 0 :(得分:0)

看起来JVM发现很难在运行时找到导致com.sun.javafx.css.converters.PaintConverter异常错误的ClassNotFoundException,这反过来导致JFoenix库抛出java.lang.NoClassDefFoundError含义在类路径中找不到类。这表明我们正在尝试加载类定义,并且该类在类路径中不存在 所以首先要确保你有正确版本的java Java 8 来支持JFoenix,他们确保JFoenix库位于你的类路径中。

答案 1 :(得分:0)

堆栈跟踪,因为它在每个完全限定的类名(例如java.lang.ClassLoader)前面加上一个模块名称(例如java.base)表示该机器正在尝试使用Java 9运行该应用程序

CSS转换器类(例如PaintConverter)从私有API(位于Java 8及更早版本中)升级到Java 9中的公共API。因此类com.sun.javafx.css.converters.PaintConverter不再存在,已被javafx.css.converter.PaintConverter取代。因此,在Java 9中运行应用程序时,会得到ClassNotFoundException

这里的底线是,如果用户更新其JVM,则使用任何非公开的API或使用第三方库的API都可能导致应用程序失败。这个问题的可能解决方案是:

  • 避免使用私有API或使用私有API的库
  • 创建和维护适用于特定JVM版本的不同版本的代码。对于您正在使用的第三方JFoenix库,Java 9有一个单独的版本,因此您可以创建使用该版本库的应用程序的Java 9版本。请注意,这不仅会给开发人员带来额外负担,而且还可能会给最终用户带来问题,最终用户将被迫更新他们使用的应用程序版本,同时更新他们的JVM。
  • 为您的应用创建"Self-Contained Application Bundle"。这会将特定JVM与您的代码捆绑在一起,因此您实际上可以控制用户运行应用程序所使用的JVM。这样做的缺点是,您需要为要支持的每个平台(Windows 32位,Windows 64位,Mac,Linux)创建不同的捆绑包,并且应用程序的大小将大幅增加(包括JVM) )。

我通常会在可能的情况下推荐第一个选项,而第三个选项则不推荐。

相关问题