0

这是教程链接

我一直在关注使用 e(fx)clipse 的 javafx 教程,但我无法启动这个教程。我的代码与他们的代码完全相同,如果我使用 Netbeans,它就可以工作,但是我在 Eclipse 中遇到了这个错误:

java.lang.ClassNotFoundException: fxmlexample.FXMLExampleController
/C:/Users/Michael/workspace/JavaFX%20Test/bin/fxmltest/fxml_example.fxml:10
  at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:726)
  at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:775)
  at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:180)
  at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:563)
  at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2744)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2723)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2709)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2696)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2685)
  at fxmltest.FXMLExample.start(FXMLExample.java:17)
  at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
  at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
  at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
  at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
  at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
  at java.lang.Thread.run(Unknown Source)
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
    at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: java.lang.ClassNotFoundException: fxmlexample.FXMLExampleController
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:726)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:775)
    at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:180)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:563)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2744)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2723)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2709)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2696)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2685)
    at fxmltest.FXMLExample.start(FXMLExample.java:17)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: fxmlexample.FXMLExampleController
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:724)
    ... 22 more

任何人都有任何解决方案可以让它与 eclipse 一起使用?

4

1 回答 1

0

好吧,我知道我做错了什么。Netbeans 会自动创建一个名为您的项目名称的包,因此当我添加控制器时fxmlexample.FXMLExampleController,它正在查看包fxmlexample,我只是使用默认包。

只需创建一个名为fxmlexample并将我的文件移动到那里的包即可修复它。

于 2013-04-06T23:13:55.227 回答