2016-04-22 10 views
1

Ich schreibe in Eclipse, und versuche, beide, javafx, fxml ad CSS zu verwenden, um ein MAD Libs Spiel für mein letztes Projekt in meiner Java Klasse zu erstellen. Ich habe die neueste Version des Szenebuilders von Gluon installiert, sowie die neueste JRE von Java. Dies ist der Code, den ichEclipse wird fxml Dateien nicht lesen/ausführen

package application; 
    import java.io.IOException; 
    import java.util.ResourceBundle; 

    import javafx.application.Application; 
    import javafx.event.ActionEvent; 
    import javafx.event.EventHandler; 
    import javafx.fxml.FXMLLoader; 
    import javafx.scene.Parent; 
    import javafx.scene.Scene; 
    import javafx.stage.Stage; 

    public class Main extends Application{ 
    public static void main(String[] args) { 
    launch(args); 
} 

@Override 
public void start(Stage primaryStage) throws IOException { 

     Parent root = FXMLLoader.load(getClass().getResource("scenebuilder.fxml")); 
     Scene scene1 = new Scene(root); 
     primaryStage.setTitle("Shane Ramos Final Project"); 
     primaryStage.setScene(scene1); 
     primaryStage.show(); 
     } 
    } 

habe Jedes Mal, wenn ich versuche, es zu laufen (es auf meiner fxml Datei aufrufe hat) es mir dieses Fehlerprotokoll in der Konsole gibt.

Exception in Application start method 
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source) 
    at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source) 
    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.launcher.LauncherHelper$FXHelper.main(Unknown Source) 
Caused by: java.lang.RuntimeException: Exception in Application start method 
    at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source) 
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.NullPointerException: Location is required. 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
    at javafx.fxml.FXMLLoader.load(Unknown Source) 
    at application.Main.start(Main.java:21) 
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source) 
    ... 1 more 
Exception running application application.Main 

Ich habe alles versucht, was ich denken kann, um dies zu beheben und bin bei einem Totalverlust. Jede Hilfe wird geschätzt. Vielen Dank!

+0

Ist scenebuilder.fmxl im selben Paket wie Main? – jns

+0

ja ich glaube, dass es ist –

Antwort

0

Sie haben einen Standort angeben zuerst:

Zum Beispiel:

private Parent root;

...

FXMLLoader loader = new FXMLLoader(); loader.setLocation(YourClass.class.getResource("yourFile.fxml"));

root = (Parent) loader.load();

Und stellen Sie sicher, dass Ihre fxml-Datei im richtigen Ordner ist.

Entsprechend Ihrem Code sollten Ihre fxml-Datei und Ihr Main.java im selben Ordner auf dem System sein.