2

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?

kibowki
  • 4,206
  • 16
  • 48
  • 74
  • 2
    The problem is `new FXMLLoader.load`. You either use the instance of `FXMLLoader` to call `load()` using new `FXMLLoader().load(...)` or call the static method using `FXMLLoader.load(...)` – ItachiUchiha Feb 17 '15 at 08:03

1 Answers1

1

Try to split it up this way:

    FXMLLoader loader = new FXMLLoader(this.getClass().getResource("DefaultFrame.fxml"));
    Parent root = (Parent) loader.load();
    dfController = loader.getController();
Juce
  • 341
  • 1
  • 8