So I created a FXML interface using JavaFX's Scene Builder tool, and I'm trying to load it via my code. However, I ran into this error when trying to load my FXML document: FXMLLoader.load can't be resolved to a type
.
Here is my code:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Driver extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Parent root = new FXMLLoader.load(getClass().getResource("interface.fxml"));
Scene scene = new Scene(root, 600, 400);
primaryStage.setTitle("Wiki Scraper");
primaryStage.setScene(scene);
primaryStage.show();
}
}
My FXML document is contained in the most top level project folder.
What am I doing incorrectly?
Try to split it up this way:
FXMLLoader loader = new FXMLLoader(this.getClass().getResource("DefaultFrame.fxml"));
Parent root = (Parent) loader.load();
dfController = loader.getController();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.