В настоящее время я создаю проект gradle и использую javafx для запуска приложения. Недавно я столкнулся с ошибкой java .lang.IllegalStateException: Местоположение не задано.
Всего 4 кода.
ui.f xml
<?xml versoin="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="comp3111.lab3.ex2.Lab3Controller">
<children>
<Button fx:id="button1" layoutX="111.0" layoutY="90.0" mnemonicParsing="false" onAction="#buttonPressed" text="Hit me" />
<Label fx:id="label1" layoutX="353.0" layoutY="162.0" text="Hi" />
</children>
</AnchorPane>
Lab3Controller. java
package comp3111.lab3.ex2;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class Lab3Controller{
@FXML
private Button button1;
@FXML
private Label label1;
@FXML
void buttonPressed(ActionEvent event){
}
}
Библиотека. java
public class Library{
public static void main(String arg[]){
comp3111.lab3.ex2.UIApplication.run(arg);
}
}
UIApplication. java
package comp3111.lab3.ex2;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class UIApplication extends Application {
@Override
public void start(Stage stage) throws Exception{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource(name:"src/main/java/ui.fxml"));
VBOX root = (VBox) loader.load();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Lab 3");
stage.show();
}
public static void run(String arg[]){
Application.launch(arg);
}
}