2

Here is my main class:

    package ProgAssignment2Package;
import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class Main extends Application {

   private Stage primaryStage;
   private AnchorPane mainLayout;
   
   public static void main(String[] args) {
       launch(args);
   }
   
   public void start(Stage primaryStage) throws IOException {
       this.primaryStage = primaryStage;
       this.primaryStage.setTitle("Real Estate Listings");
       showMainGUI();
   }
  
   private void showMainGUI() throws IOException {
       FXMLLoader loader = new FXMLLoader();
       loader.setLocation(getClass().getClassLoader().getResource("/MainGUI.fxml"));
       mainLayout = loader.load();
       Scene scene = new Scene(mainLayout);
       primaryStage.setScene(scene);
       primaryStage.show();
   }


}

Here is my FXML file:

   

     <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.text.*?>
    <?import javafx.scene.control.*?>
    <?import java.lang.*?>
    <?import javafx.scene.layout.*?>
    <?import javafx.scene.layout.AnchorPane?>
    
    <AnchorPane maxHeight="600.0" maxWidth="500.0" minHeight="600.0" minWidth="500.0" prefHeight="600.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="realEstate.MainController">
    <children>
    <Button layoutX="222.0" layoutY="555.0" mnemonicParsing="false" onAction="#reset" text="Reset">
    <font>
    <Font size="16.0" />
    </font></Button>
    <Button alignment="CENTER" defaultButton="true" layoutX="25.0" layoutY="504.0" mnemonicParsing="false" onAction="#calculate" text="Find my dream house!">
    <font>
    <Font size="16.0" />
    </font></Button>
    <Button fx:id="notMyDream" alignment="CENTER" disable="true" layoutX="224.0" layoutY="504.0" mnemonicParsing="false" onAction="#findNext" text="Not my dream - Find me another!">
    <font>
    <Font size="16.0" />
    </font></Button>
    <TextField fx:id="minPriceField" layoutX="233.0" layoutY="79.0" />
    <Label layoutX="142.0" layoutY="25.0" text="Real Estate Listings">
    <font>
    <Font name="System Bold" size="24.0" />
    </font>
    </Label>
    <TextField fx:id="maxPriceField" layoutX="233.0" layoutY="122.0" />
    <TextField fx:id="minAreaField" layoutX="233.0" layoutY="165.0" />
    <TextField fx:id="maxAreaField" layoutX="233.0" layoutY="209.0" />
    <TextField fx:id="minBedsField" layoutX="233.0" layoutY="251.0" />
    <TextField fx:id="maxBedsField" layoutX="233.0" layoutY="294.0" />
    <Label layoutX="97.0" layoutY="81.0" text="Minimum Price:" textAlignment="RIGHT">
    <font>
    <Font size="18.0" />
    </font>
    </Label>
    <Label layoutX="97.0" layoutY="124.0" text="Maximum Price:" textAlignment="RIGHT">
    <font>
    <Font size="18.0" />
    </font>
    </Label>
    <Label layoutX="97.0" layoutY="167.0" text="Minimum Area:" textAlignment="RIGHT">
    <font>
    <Font size="18.0" />
    </font>
    </Label>
    <Label layoutX="97.0" layoutY="253.0" text="Minimum Beds:" textAlignment="RIGHT">
    <font>
    <Font size="18.0" />
    </font>
    </Label>
    <Label layoutX="97.0" layoutY="211.0" text="Maximum Area:" textAlignment="RIGHT">
    <font>
    <Font size="18.0" />
    </font>
    </Label>
    <Label layoutX="97.0" layoutY="296.0" text="Maximum Beds:" textAlignment="RIGHT">
    <font>
    <Font size="18.0" />
    </font>
    </Label>
    <Label layoutX="25.0" layoutY="395.0" text="Chosen Home:">
    <font>
    <Font size="18.0" />
    </font>
    </Label>
    <TextField fx:id="outputField" editable="false" layoutX="151.0" layoutY="393.0" prefHeight="31.0" prefWidth="318.0" />
    <Label fx:id="errorField" alignment="CENTER" layoutX="54.0" layoutY="450.0" prefHeight="31.0" prefWidth="394.0" text="No error" textAlignment="CENTER" textFill="RED" visible="false">
    <font>
    <Font name="System Bold" size="15.0" />
    </font>
    </Label>
    </children>
    </AnchorPane>

Here is my error:


    Exception in Application start method
    java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
    Caused by: java.lang.RuntimeException: Exception in Application start method
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
        at java.base/java.lang.Thread.run(Thread.java:832)
    Caused by: java.lang.IllegalStateException: Location is not set.
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2541)
        at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2517)
        at ProgAssignment2Package.Main.showMainGUI(Main.java:28)
        at ProgAssignment2Package.Main.start(Main.java:22)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
        ... 1 more
    Exception running application ProgAssignment2Package.Main

I've posted about this earlier but had an incorrect title, misleading people to think the problem was elsewere. I have tried multiple ways of calling to the FXML file but to no avail, how can I properly reference it?

Is it possible I have an error in another class? I only put the Main one because based on the error it looks as though that is the class that is failing.

Memzi
  • 27
  • 6
  • https://stackoverflow.com/questions/64835996/java-fxml-error-exception-in-application-start-method – Grzegorz Oledzki Nov 16 '20 at 22:13
  • Have you seen https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other ? – Grzegorz Oledzki Nov 16 '20 at 22:14
  • Does this answer your question? [JavaFX Location is not set error message](https://stackoverflow.com/questions/17228487/javafx-location-is-not-set-error-message) – takendarkk Nov 16 '20 at 22:14

0 Answers0