0

I'm very, VERY new to using JavaFX and FXML in general, and I've run into a bit of a problem that I've not been able to solve either through repeated Google searches, or searches here on Stack Exchange. While others have had similar problems, I haven't been able to replicate their solutions within my own project.

Right now, I'm mostly just trying to test JavaFX with FXML and get a feel for it... however I can't even get it to load, as FXMLLoader is giving me the following error.

javafx.fxml.LoadException: /C:/Users/Dylon/workspace/Convergence_titanExplorationModule/bin/com/test/fxml/ExplorationModuleUI.fxml

at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source) at javafx.fxml.FXMLLoader.importClass(Unknown Source) at javafx.fxml.FXMLLoader.processImport(Unknown Source) at javafx.fxml.FXMLLoader.processProcessingInstruction(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.load(Unknown Source) at com.test.fxml.Main.start(Main.java:14) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException at javafx.fxml.FXMLLoader.loadType(Unknown Source) ... 21 more

Now, here's the code I'm working with...

package com.test.fxml;

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


    public class Main extends Application {
        @Override
        public void start(Stage primaryStage) {
            try {
                Parent root = FXMLLoader.load(getClass().getResource("/com/test/fxml/ExplorationModuleUI.fxml"));
                Scene scene = new Scene(root,400,400);
                primaryStage.setScene(scene);
                primaryStage.show();
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

Here's my FXML file, named ExplorationModuleUI.fxml...

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.*?>
<?import javafx.scene.control*?>

<BorderPane xmlns:fx="http://javafx.com/fxml/1">
    <TOP>
        <HBox>
            <Button text = "test"/>
        </HBox>
    </TOP>
</BorderPane>

Finally, here's how I have things laid out in regards to folders.

I can't post images yet so here's a link to one instead

Any help is greatly appreciated. I honestly haven't been able to figure out why it doesn't work even after digging about for a couple of hours tonight. I've tried other solutions I've found on here and in Google searches, but nothing has worked yet. If you have any questions feel free to ask and I'll get back to you as soon as I can in the morning.

4

1 回答 1

0

First, your second import is missing a dot between control and *, it should be import javafx.scene.control.*

Second, TOP is not a valid element for fxml, use top instead (all lowercase).

于 2015-12-31T06:16:57.603 回答