InvocationTargetException, wenn ein javafx-Programm
So funktionierte dies in dem Beispiel von javafx, wenn Mein pc hatte jdk 1.7.0 so kann dies die neue version von FX in java8 jedoch;
Bekomme ich einen schönen stack-trace
jfx-project-run:
Executing E:\workspace\PathFinderApp\dist\run1095471771\PathFinderApp.jar using platform C:\Program Files\Java\jdk1.8.0\jre/bin/java
Exception in Application start method
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:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:367)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:305)
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:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:894)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
at java.lang.Thread.run(Thread.java:744)
Caused by: javafx.fxml.LoadException:
file:/E:/workspace/PathFinderApp/dist/run1095471771/PathFinderApp.jar!/com/rpg/gui/main.fxml:11
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:937)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:976)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:738)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3230)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3191)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3164)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3140)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3120)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3113)
at com.rpg.gui.GUI.loadMainPane(GUI.java:34)
at com.rpg.gui.GUI.initialize(GUI.java:20)
at Main.start(Main.java:20)
at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
... 1 more
Caused by: java.lang.InstantiationException: com.rpg.gui.MainController
at java.lang.Class.newInstance(Class.java:418)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:932)
... 26 more
Caused by: java.lang.NoSuchMethodException: com.rpg.gui.MainController.<init>()
at java.lang.Class.getConstructor0(Class.java:2971)
at java.lang.Class.newInstance(Class.java:403)
... 28 more
Exception running application Main
Java Result: 1
grundsätzlich etwas zu mir sagt ist hier falsch "com/rpg/gui/main.fxml:11"
und diese Linie ist
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="com.rpg.gui.MainController">
damit ich herausfinden kann, dass es nicht wie etwas zu tun mit dem Haupt-controller, so dass es hat etwas zu tun mit dem laden der fxml und den controller richtig? aber das ist ungefähr, wo meine Ideen am Ende
MainController mainController = new MainController(path);
Pane mainPane = FXMLLoader.load(getClass().getResource("main.fxml"));
Window.setMainController(mainController);
Window.swap(path+"content.fxml");
dass ist die Methode, die es wirft alles, was in jemand Erfahrung in javaFX oder im Falle von änderungen in java8, würde dies tun??
InformationsquelleAutor der Frage Matthew Optional Meehan | 2014-04-17
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ihre
MainController
nicht über einen null-argument-Konstruktor. Wenn dieFXMLLoader
trifft auf einefx:controller
Attribut auf das root-element, es wird versucht eine Instanz zu schaffen, dass der controller durch (effektiv) Aufruf der zero-argument-Konstruktor der Klasse angegeben, die in dem Attribut.Dieses Problem zu beheben (der einfachste Weg), entfernen Sie die
fx:controller
Attribut aus der FXML-Dateiund setzen Sie den regler "von hand" auf dieFXMLLoader
. Sie müssen zum erstellen einesFXMLLoader
Instanz, anstatt sich auf den statischenload(...)
Methode:InformationsquelleAutor der Antwort James_D
Ich Stand vor dem gleichen problem und will Euch ein bisschen damit zu tun haben. Ich bin mit java 8 und Netbeans 8.1 und wenn ich Sie erstellt eine javafx-FXML-Anwendung ich habe diese ein.
Hier sind einige Tipps:
Können Sie festlegen, controller entweder in
fxml
- Datei oder inmain
Klasse.Wenn Sie möchten, zu definieren controller in
main
Klasse verwenden Sie die beschriebene Methode von @James_D. Wenn Sie möchten, um zu definieren, infxml
Datei alsfx:controller
Attribut alsund in der main-Klasse Referenz als
Hoffe, es würde jemand helfen.
InformationsquelleAutor der Antwort Inzimam Tariq IT
Ich auch die Begegnung, die eine Menge... Es scheint ein bug in der Scenebuilder/netbeans 8, wo Sie beim speichern im Scenebuilder, es schafft eine andere xmlns:fx="..." so, dass ein Problem sein kann...
Auch, Blick auf fxml - ich habe mit java8, habe ich diese:
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
wobei mir aufgefallen ist das:
xmlns:fx="http://javafx.com/fxml"
InformationsquelleAutor der Antwort jdub1581
Du verwendet
Versuchen
InformationsquelleAutor der Antwort idzik78
Wenn Einer nicht beheben das problem, indem Sie die folgenden Antworten, Der einfache Weg ist die Schaffung von neuen fxml Leere Klasse dann klicken Sie auf Bearbeiten der fxml causin das problem und kopieren Sie den xml-code auf die neue Klasse .
Gehen Sie auf die start () - methode, ändern Sie die:
zu
InformationsquelleAutor der Antwort Abderrahmane