JavaFX java.lang.IllegalStateException: Location is not set.

MARJAVA

Aktives Mitglied
Hallo zusammen,

nach dem erfolgreichen Kompilieren (ohne Fehlermeldung) meines JavaFX-Programms habe ich es auch als ausführende Datei exportiert.

Allerdings kommt nun nach dem Remotedebugging der Anwendung eine IllegalStateException Location not set.
Die exakte Zeilennummer wird nicht angezeigt, aber es kann sich eigentlich nur um die Location der FXML-Datei handeln.
Java:
java.lang.IllegalStateException: Location is not set.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at de.markusc.Main.initRootLayout(Main.java:198)
    at de.markusc.Main.start(Main.java:90)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    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.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)

Um eventuellen Problemen unter Windows mit dem Fileseparator zu entgehen, habe ich den LocationString zerlegt und mit File.Separator() ausgestattet.
Das führt allerdings im Eclipse zu eben dieser Fehlermeldung.

Hat jemand einen Vorschlag warum die Location der FXML-Datei nicht angenommen wird?
 
Die exakte Zeilennummer wird nicht angezeigt, aber es kann sich eigentlich nur um die Location der FXML-Datei handeln.
Doch: at de.markusc.Main.initRootLayout(Main.java:198)

Um eventuellen Problemen unter Windows mit dem Fileseparator zu entgehen, habe ich den LocationString zerlegt und mit File.Separator() ausgestattet.
Das führt allerdings im Eclipse zu eben dieser Fehlermeldung.
Für intern benutzte Pfade immer '/' verwenden.
Nur bei Pfaden, die dem Nutzer angezeigt werden, hat die Nutzung von File.Separator Sinn.

Hat jemand einen Vorschlag warum die Location der FXML-Datei nicht angenommen wird?
Weil der Pfad falsch übergeben wird. Höchstwahrscheinlich, weil du nicht Class#getResource benutzt - aber dafür müsste man den Code sehen 😉
 
Leider muss ich konstatieren, dass die Fehlermeldung aus dem Eclipse stammt und nicht aus der cmd.
Die Art der Fehlermeldung ist jedoch die selbe wie beim Remotedebugging.
Sorry für das Missverständnis: Hier die eigentliche Fehlermeldung:
Code:
Microsoft Windows [Version 10.0.17134.112]
(c) 2018 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\Markus Christian>cd C:\Users\Markus Christian\EclipseWorkspaceMarkus\Bibliothek\build\deploy

C:\Users\Markus Christian\EclipseWorkspaceMarkus\Bibliothek\build\deploy>java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5555 -jar Bibliothek.jar
Listening for transport dt_socket at address: 5555
Anfang: Methode initRootLayout
Schritt 1
Anfang: Methode getBuchFilepath
Ende: Methode getBuchFilepath
C:\Users\Markus Christian\Desktop\test\books2.xml
Anfang: Methode load
Anfang: Methode setBuchFilepath
Ende: Methode setBuchFilepath
size: 15
class de.markusc.model.Buch
class com.sun.javafx.collections.ObservableListWrapper
ArcGIS 10.3
class com.sun.javafx.collections.ObservableListWrapper
Ausgleichungsrechnung
class com.sun.javafx.collections.ObservableListWrapper
B for Business
class com.sun.javafx.collections.ObservableListWrapper
Einführung in die Fernerkundung
class com.sun.javafx.collections.ObservableListWrapper
Formeln und Tabellen für die Sekundarstufen I und II
class com.sun.javafx.collections.ObservableListWrapper
GNSS 2009: Systeme, Dienste, Anwendungen: Beiträge zum 83. DVW-Seminar am 18. und 19. März 2009 in Dresden (Schriftenreihe des DVW, Band 57)
class com.sun.javafx.collections.ObservableListWrapper
Integrierte Navigationssysteme
class com.sun.javafx.collections.ObservableListWrapper
Learning English, Grundgrammatik, Ausgabe für Gymnasien
class com.sun.javafx.collections.ObservableListWrapper
Mathematik für jedermann
class com.sun.javafx.collections.ObservableListWrapper
OpenStreetMap: Die freie Weltkarte nutzen und mitgestalten
class com.sun.javafx.collections.ObservableListWrapper
Pilze
class com.sun.javafx.collections.ObservableListWrapper
Steve Jobs
class com.sun.javafx.collections.ObservableListWrapper
Vermessung und Ortung mit Satelliten
class com.sun.javafx.collections.ObservableListWrapper
Vermessungskunde 1
class com.sun.javafx.collections.ObservableListWrapper
Vermessungskunde, 2 Tle, Tl.2
Ende: Methode load
Anfang: Methode sortiere
Ende: Methode sortiere
Anfang: Methode ShowBooks
java.lang.IllegalStateException: Location is not set.
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
        at de.markusc.Main.showBooks(Unknown Source)
        at de.markusc.Main.initRootLayout(Unknown Source)
        at de.markusc.Main.start(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        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.lambda$null$147(WinApplication.java:177)
        at java.lang.Thread.run(Unknown Source)
Der Code der Main-Klasse ist folgender:
Java:
package de.markusc;
   
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
import java.util.prefs.Preferences;

import javax.swing.event.HyperlinkEvent.EventType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import de.markusc.controller.ExcelFileManager;
import de.markusc.model.Buch;
import de.markusc.model.BuchListWrapper;
import de.markusc.view.BuchUebersichtController;
import de.markusc.view.BuchhalterController;
import de.markusc.view.RegalBodenController;
import de.markusc.view.RootLayoutController;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;


public class Main extends Application {

    private Stage primaryStage;
    private BorderPane rootLayout;
    private AnchorPane buchHalter;
    private ScrollPane buchübersichtScrollpane,regalbodenScrollpane;
    private ObservableList<Buch> buchListe= FXCollections.observableArrayList();
    private ObservableList<Buch> buchListeX= FXCollections.observableArrayList();
    private Vector<ObservableList<Buch>> BuchKategorien;
    private Vector<String> vKat;
   
   
    public Main() {

       
       
    }

   

   
    public ObservableList<Buch> getBuchData() {
        return buchListe;
    }
   
    @Override
    public void start(Stage primaryStage) {
        try {
           
           

            this.primaryStage=primaryStage;
            this.primaryStage.setTitle("Bibliothek");
           
            initRootLayout();
           
           
           
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
   
    public void importXLS(File file) {
        try {
           
       
       
        


        if(file!=null) {
            ExcelFileManager efM=new ExcelFileManager(file);
           
            buchListe.clear();
            buchListe= FXCollections.observableArrayList();
            buchListe=efM.readFile();

            sortiere(buchListe);
            showBooks();

       
        }
        }catch(Exception e) {
            e.printStackTrace();
        }

       
       
           
    }
   
    public void exportXLS(File file) {

       


        if(file!=null) {
            ExcelFileManager efM=new ExcelFileManager(file);
           
            efM.saveFile(buchListe);
           
        }
    }


    private void sortiere(ObservableList<Buch> buchListe2) {
        System.out.println("Anfang: Methode sortiere ");
        boolean enthaelt=false;
        vKat=new Vector<String>();
        vKat.add(((Buch)buchListe2.get(0)).getKategorie());
        for(int i=1;i<buchListe2.size();i++) {
            enthaelt=false;
            String kategorie=buchListe2.get(i).getKategorie();
           
            for(int j=0; j<vKat.size();j++) {
               
                if(kategorie.equals(vKat.get(j))) {
                    enthaelt=true;
                   
                }
            }
            if(enthaelt==false&&!kategorie.equals("")) {
               
                vKat.add(kategorie);
                enthaelt=false;
            }

        }
        BuchKategorien=new Vector<ObservableList<Buch>>();
        for(int i=0; i<vKat.size();i++) {
            buchListeX= FXCollections.observableArrayList();
            BuchKategorien.add(buchListeX);
        }
        for(int i=0; i<buchListe2.size();i++) {
            Buch buch=(Buch)buchListe2.get(i);
           
            for(int j=0;j<vKat.size();j++) {
                ObservableList<Buch> buchListe3=(ObservableList<Buch>) BuchKategorien.get(j);
                if(buch.getKategorie().equals(((String)vKat.get(j)))) {
                    buchListe3.add(buch);
                   
                }
            }
        }
        System.out.println("Ende: Methode sortiere ");   
    }
   
    public void beenden() {
        primaryStage.close();
    }
    public void initRootLayout() {
       

       
        try {
            System.out.println("Anfang: Methode initRootLayout");
            FXMLLoader loader= new FXMLLoader();
            loader.setLocation(Main.class.getResource("view/RootLayout.fxml"));
           
           
           
            rootLayout= (BorderPane) loader.load();
           
            Scene scene=new Scene(rootLayout);///main/java/de/markusc/
            String urlString="application.css";
            scene.getStylesheets().add(Main.class.getResource(urlString).toExternalForm());
           
            primaryStage.setScene(scene);
           
            RootLayoutController controller = loader.getController();
            controller.setMain(this);
           
            primaryStage.show();
           
           
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("Schritt 1");
        File file = getBuchFilePath();
        if (file != null) {
            System.out.println(file.getAbsolutePath().toString());
            loadBuchDataFromFile(file);
        }

        sortiere(buchListe);
       
        showBooks();
       
        System.out.println("Ende: Methode RootLayout ");
    }
   
    public Stage getPrimaryStage() {
        return primaryStage;
    }
   
    public void showBooks() {
       
        System.out.println("Anfang: Methode ShowBooks ");
        try {
           

           

       

           
           
            // lädt die BücherÜbersicht
            FXMLLoader loader2 = new FXMLLoader();
            loader2.setLocation(Main.class.getResource("view/BuchUebersicht.fxml"));
            AnchorPane buchUebersicht = (AnchorPane) loader2.load();

            rootLayout.setCenter(buchUebersicht);

            // Give the controller access to the main app.
            BuchUebersichtController controller = loader2.getController();
            controller.setMain(this);
            ScrollPane buchübersichtScrollpane =controller.getScrollpane();
           
           
           

           
            VBox vb= new VBox();
           
            Vector<HBox> boxVector=new Vector<HBox>();
            HBox hb=null;
         
           

           


           
            for(int j=0; j<BuchKategorien.size(); j++) {
               
                hb= new HBox();
               
               
                ObservableList<Buch> buchListe=(ObservableList<Buch>)BuchKategorien.get(j);
                for(int i=0; i<buchListe.size(); i++) {
                    int k=i;
                    FXMLLoader loaderBuchHalter = new FXMLLoader();
                    loaderBuchHalter.setLocation(Main.class.getResource("view/BuchHalter.fxml"));
                    buchHalter = (AnchorPane) loaderBuchHalter.load();
                    buchHalter.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, new CornerRadii(5), BorderStroke.THIN)));

                    
                   
                   
                    BuchhalterController buchhalterController=loaderBuchHalter.getController();
                   
                    buchhalterController.setMain(this);
                    buchhalterController.showBook(buchListe.get(i));
                   
                    hb.getChildren().add(buchHalter);
                   
                    buchHalter.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
                          @Override
                         public void handle(MouseEvent e) {
                           
                             
                              controller.setBuch(buchhalterController.getBook());
                              final Canvas canvas=controller.getCanvas();
                              final GraphicsContext gc=canvas.getGraphicsContext2D();
                              //String urlString=getClass().getClassLoader().getResource("C:/Users/Markus Christian/EclipseWorkspaceMarkus/Bibliothek/target/classes/main/resources/de/markusc/nachrichten-aus-einem-unbekannten-universum-frank-schaetzing.jpg").toString().replace("%20", " ");
                       
                              FileInputStream inputstream=null;
                        try {
                            String s=System.getProperty("user.home")+"/"+buchListe.get(k).getCover();
                           
                            inputstream = new FileInputStream(s);
                        } catch (FileNotFoundException e1) {
                            // TODO Automatisch generierter Erfassungsblock
                            e1.printStackTrace();
                        }
                              Image image = new Image(inputstream);
                              gc.drawImage(image, 0, 0, 200, 200);
                             
                           

                         }
                      });

                }
                boxVector.add(hb);
               
                FXMLLoader loaderRegalboden = new FXMLLoader();
                loaderRegalboden.setLocation(Main.class.getResource("view/Regalboden.fxml"));
                AnchorPane regalboden = (AnchorPane) loaderRegalboden.load();
               
                RegalBodenController regalbodenController= loaderRegalboden.getController();
                regalbodenController.setLabelTxt((String)(vKat.get(j)));
                regalbodenController.setMain(this);
               
                ScrollPane regalbodenScrollpane=regalbodenController.getScrollPane();
                regalbodenScrollpane.setContent((HBox)boxVector.get(j));
               
               
               
               

                vb.getChildren().add(regalboden);
               
               
            }

               
           
            buchübersichtScrollpane.setContent(vb);
           


           

           

        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("Ende: Methode ShowBooks ");
       
    }
   
    public void loadBuchDataFromFile(File file) {
        System.out.println("Anfang: Methode load");
        try {
            JAXBContext context = JAXBContext
                    .newInstance(BuchListWrapper.class);
            Unmarshaller um = context.createUnmarshaller();

            // Reading XML from the file and unmarshalling.
            BuchListWrapper wrapper = (BuchListWrapper) um.unmarshal(file);

            buchListe.clear();
            buchListe= FXCollections.observableArrayList();
            buchListe.addAll(wrapper.getBuecher());
            //buchListe= (ObservableList<Buch>)wrapper.getBuecher();
           
            // Save the file path to the registry.
            setBuchFilePath(file);
            System.out.println("size: "+buchListe.size());
            System.out.println(((Buch)buchListe.get(0)).getClass());
            for(int i=0;i<buchListe.size();i++) {
                System.out.println(buchListe.getClass());
                System.out.println(((Buch)buchListe.get(i)).getTitel());
            }


        } catch (Exception e) {
            e.printStackTrace();// catches ANY exception
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error");
            alert.setHeaderText("Could not load data");
            alert.setContentText("Could not load data from file:\n" + file.getPath());

            alert.showAndWait();
        }
        System.out.println("Ende: Methode load");
    }
   
    public void setBuchFilePath(File file) {
        System.out.println("Anfang: Methode setBuchFilepath");
        Preferences prefs = Preferences.userNodeForPackage(Main.class);
        if (file != null) {
            prefs.put("filePath", file.getPath());

            // Update the stage title.
            primaryStage.setTitle("Bibliothek - " + file.getName());
        } else {
            prefs.remove("filePath");

            // Update the stage title.
            primaryStage.setTitle("Bibliothek");
        }
        System.out.println("Ende: Methode setBuchFilepath");
    }
   
    public File getBuchFilePath() {
        System.out.println("Anfang: Methode getBuchFilepath");
        Preferences prefs = Preferences.userNodeForPackage(Main.class);
        String filePath = prefs.get("filePath", null);
        if (filePath != null) {
            System.out.println("Ende: Methode getBuchFilepath");
            return new File(filePath);
        } else {
            System.out.println("Ende: Methode getBuchFilepath");
            return null;
        }
       
    }
   
    public void saveBuchDataToFile(File file) {
        try {
            System.out.println("Anfang: Methode saveBuchFilepath");
            JAXBContext context = JAXBContext
                    .newInstance(BuchListWrapper.class);
            Marshaller m = context.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            System.out.println(buchListe.size());
            // Wrapping our person data.
            BuchListWrapper wrapper = new BuchListWrapper();
            wrapper.setBuecher(buchListe);

            // Marshalling and saving XML to the file.
            m.marshal(wrapper, file);



            System.out.println("Anfang: Methode saveBuchFilepath");
            // Save the file path to the registry.
            setBuchFilePath(file);
           
        } catch (Exception e) { // catches ANY exception
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error");
            alert.setHeaderText("Could not save data");
            alert.setContentText("Could not save data to file:\n" + file.getPath());

            alert.showAndWait();
        }
    }
   
   
    public static void main(String[] args) {
        launch(args);
    }
}
 
Die Dateien sind alle in der Jar vorhanden.
Wie kann ich genau in Eclipse die Kompilierung so setzen, dass die Source angegeben wird?

Nach dem Verschieben der BuchUebersicht.fxml ins Verzeichnis der Main.class und dem Anpassen des Pfades tritt der Fehler weiterhin auf. Es scheint also nicht am Pfad zu liegen.

Es geht genau um diese Source: "at de.markusc.Main.showBooks(Unknown Source)"
 
Ok, das setzen der CompilerInformation hat funktioniert

Code:
java.lang.IllegalStateException: Location is not set.
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
        at de.markusc.Main.showBooks(Main.java:239)
        at de.markusc.Main.initRootLayout(Main.java:215)
        at de.markusc.Main.start(Main.java:80)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        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.lambda$null$147(WinApplication.java:177)
        at java.lang.Thread.run(Unknown Source)

es geht um folgende Zeile:
Java:
            AnchorPane buchUebersicht = (AnchorPane) loader2.load();
 
Jetzt nachdem die Zeilennummer angegeben ist, bin ich auf den Fehler gestoßen. Im genannten Fehler war ein Großbuchstabe statt einem Kleinbuchstaben der auslösende Faktor.

Irritierend ist für mich allerdings, dass der Fehler beim Compilieren und Interpreteraufruf in eclipse nicht auftrat.

thx @mrBrown
 
Jetzt nachdem die Zeilennummer angegeben ist, bin ich auf den Fehler gestoßen. Im genannten Fehler war ein Großbuchstabe statt einem Kleinbuchstaben der auslösende Faktor.
Was war denn falsch geschrieben?

Irritierend ist für mich allerdings, dass der Fehler beim Compilieren und Interpreteraufruf in eclipse nicht auftrat.
Beim Kompilieren wird der Code nichts ausgeführt, da kann sowas dann nicht passieren 😉

Und in Eclipse wird das z.T. anders ausgeführt (u.a. ist es nicht als Jar gepackt), deshalb treten solche Fehler manchmal nicht auf.
 

Zurück
Oben