I'm running an FXML project and I can't load my fxml files, IntelliJ keeps indicating there is something wrong with my AnchorPane tag, however this was all generated by scene builder. This error even shows up for fxml files created by IntelliJ. The issue seems to be xmlns="http://javafx.com/javafx/19" within the AnchorPane tag at least that's where the compiler is pointing to.
I'm running IntelliJ 2022 with JDK 17.0.4.1 with JavaFX 19 using Maven, and I'm using scene builder 19.
here is my fxml code
`
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.LoginController">
<children>
<VBox prefHeight="400.0" prefWidth="600.0" />
<TextField id="Username" layoutX="115.0" layoutY="60.0" prefHeight="25.0" prefWidth="126.0" promptText="user@account.com" />
<Label layoutX="39.0" layoutY="64.0" prefHeight="17.0" prefWidth="63.0" text="Username" />
<Label layoutX="39.0" layoutY="116.0" text="Password" />
<TextField id="password" layoutX="115.0" layoutY="112.0" prefHeight="25.0" prefWidth="126.0" />
<Button id="login" layoutX="132.0" layoutY="210.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="85.0" text="Login" />
<Label layoutX="39.0" layoutY="153.0" prefHeight="17.0" prefWidth="63.0" text="Location" />
<TextField id="Location" disable="true" layoutX="115.0" layoutY="149.0" prefHeight="25.0" prefWidth="126.0" promptText="Your location here" />
<Label id="ErrorMessage" alignment="CENTER" disable="true" layoutX="91.0" layoutY="183.0" prefHeight="17.0" prefWidth="187.0" text="Error Label" textAlignment="CENTER" textFill="#e10724">
<font>
<Font name="System Italic" size="12.0" />
</font>
</Label>
</children>
</AnchorPane>
`
and here is my java code
`
package controllers;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.net.URL;
public class LoginController {
@FXML
private TextField Username;
//Buttons
@FXML
private TextField Password;
@FXML
private TextField Location;
@FXML
private Label ErrorMessage;
@FXML
private Button Login;
public void BeginStart(){
//Loader
try {
//debugging fxml path
URL uri = getClass().getResource("/views/login.fxml");
System.out.println(uri);
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/views/login.fxml"));
Scene scene = new Scene(fxmlLoader.load());
Stage stage = new Stage();
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
/*Parent root = loader.load();
Stage stage = new Stage();
stage.setTitle("Scheduler Login");
stage.setScene(new Scene(root));
stage.show();*/
}catch(Exception e){
System.out.println("Failed to load login.fxml");
System.out.println("Exception: " + e.toString());
}
}
}
`
uri is non-null so there appears to be no problem with the file path.
Previously I've had the "uri not registered" error before I deleted the javaFX files included with Maven, and used a local copy of the JavaFX19 library, along with the proper JVM arguments.
Note: the image I included is from a previous version of my project. Under resources "controllers" is actually supposed to be "views".