JavaFX Ein View vorschalten Exception

Harry05

Bekanntes Mitglied
Aloha Leute,

wie kriege ich die view vorgeschaltet ?
Java:
public void neuesProfil() {
      try {
    // Load NeuesProfil overview.
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(Main.class.getResource("../view/NeuesProfil.fxml"));
    AnchorPane neuesProfilOverview = (AnchorPane) loader.load();

    // Set NeuesProfil overview into the center of root layout.
    rootLayout.setCenter(neuesProfilOverview);
    } catch (IOException e) {
    e.printStackTrace();
    }
  }

java.lang.NullPointerException
at de.dokumenten.controller.Main.neuesProfil(Main.java:68)
at de.dokumenten.controller.Main.start(Main.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$49(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:745)

Code:
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <TextField accessibleHelp="ycyxcyxc" layoutX="29.0" layoutY="36.0" promptText="Datenbank Name" text="Datenbank Name" />
      <TextField layoutX="29.0" layoutY="93.0" prefHeight="26.0" prefWidth="355.0" promptText="Der Pfad wo die Datenbank gespeichert verden soll" />
      <Button layoutX="421.0" layoutY="93.0" mnemonicParsing="false" text="Durchsuchen" />
      <Button layoutX="269.0" layoutY="360.0" mnemonicParsing="false" text="Profil Erstellen" />
      <TextField layoutX="29.0" layoutY="154.0" promptText="Benutzer Name" />
      <TextField layoutX="29.0" layoutY="207.0" prefHeight="26.0" prefWidth="446.0" promptText="Optional mehrere Mitbenutzer mit Kommer (,) trennen (Harry,Jan)" />
      <Label layoutX="231.0" layoutY="14.0" text="Neues Profil Erstellen" />
   </children>
</AnchorPane>
 
Was heißt vorschalten?
Meinst du damit anzeigen?
Mit vorschalten meine ich, du hast eine Menu leiste unter dem Fenster Als (Daten/speichern,Daten/ Speichern unter,Daten/laden, Hilfe/über uns...) über dieses Fenster werden dann mehrere Fenster Gelegt(vorgeschalten). So das ich für die Menu leiste einmal die Logik Programmieren muss 😉
 
Wo genau liegt denn nun eigentlich das Problem? Nur an der Exception welche du im Eingangspost gepostet hast?
Wenn ja dann musst du schauen welches der Objekte in der Methode neuesProfil null ist, leider können wir schwer raten welche Zeile, Zeile 68 ist 😉
 
Ich glaube mit "vorschalten", was so oder so ein falscher Begriff wäre, ist die Trennung der UI in separate Einheiten gemeint. Also wenn man sich das Code-Makery-Beispiel anschaut.
Wie @Joose schon sagt: Kümer dich um die NullPointerException in Zeile 68 der Main-Klasse und git ist es. Ich vermute, rootLayout ist noch nicht initialisiert.
 
Also,
erst mal danke an alle Habe den Fehler behoben.

ich habe es In der Main class als privat BorderPane rootLayout deklariert diese in einer Anderen Methode überschrieben z.b BorderPane rootLayout = (BorderPane) loader.load();
 

Neue Themen


Zurück
Oben