【问题标题】:Can't seem to run JavaFX project in Eclipse似乎无法在 Eclipse 中运行 JavaFX 项目
【发布时间】:2015-09-07 14:15:23
【问题描述】:

我使用的是 Ubuntu 14.04 64 位。我为 Java 安装了 Oracle-8 并从 http://efxclipse.bestsolution.at/ 下载了 e(fx)clipse 包。

但是,现在我遇到了这个错误消息:

Exception in Application constructor
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)

Caused by: java.lang.RuntimeException: Unable to construct Application instance: class ui.project.Main
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:819)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$null$50(GtkApplication.java:139)
    ... 1 more

Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/Utils
    at org.controlsfx.tools.Platform.getCurrentPlatform(Platform.java:65)
    at org.controlsfx.tools.Platform.<clinit>(Platform.java:41)
    at org.controlsfx.dialog.HeavyweightDialog.<clinit>(HeavyweightDialog.java:72)
    at org.controlsfx.dialog.DialogFactory.createDialog(DialogFactory.java:58)
    at org.controlsfx.dialog.Dialog.<init>(Dialog.java:295)
    at org.controlsfx.dialog.Dialogs.buildDialog(Dialogs.java:1086)
    at org.controlsfx.dialog.Dialogs.showCommandLinks(Dialogs.java:692)
    at ui.project.Main.welcomeWindow(Main.java:175)
    at ui.project.Main.<init>(Main.java:64)
    ... 13 more

Caused by: java.lang.ClassNotFoundException: com.sun.javafx.Utils
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 22 more
Exception running application ui.project.Main

Main 64 在第 175 行调用方法welcomeWindow,其中包括这一行:

Action response = Dialogs.create()
            .title("Welcome to the Dolphin UI")
            .masthead(null)
            .message("Please select an option to proceed.")
            .showCommandLinks(links.get(3), links);

【问题讨论】:

  • 您介意显示mcve 吗?
  • 代码本身非常大,不可能。我的 Main 类似乎有两个错误,我已在上面列出。
  • 我想我最大的问题是这一行:java.lang.ClassNotFoundException: com.sun.javafx.Utils 但我不知道如何解决它。
  • 你设法让 javafx 工作了吗?
  • 例如,你能让this example from oracle documentation工作吗?

标签: java eclipse javafx


【解决方案1】:

问题是 com.sun.javafx.Utils 类在 Java 8 的更新 60 中被移到了 com.sun.javafx.util.Utils 包中。

我看到您在代码中使用了 ControlsFX。然后,拿个新版本的ControlsFX解决这个问题。

更多信息: https://bitbucket.org/controlsfx/controlsfx/issues/526/comsunjavafxutils-changes-to

【讨论】:

【解决方案2】:

在使用三种不同的操作系统(Ubuntu 32、64 和 Windows 8.1)花了大约 8 个小时之后,问题出在 Java 上。显然,8u40 之后的任何版本都不适用于此。

【讨论】:

  • 那么,答案是“如果使用 Java 8,就不能使用 JavaFX”?这是一个非常不清楚的答案。
  • 您当然可以使用它,但我使用的特定代码在 8u40 之后无法使用
猜你喜欢
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-25
  • 1970-01-01
相关资源
最近更新 更多