'JavaFX Loader returning an IOException
Trying to load an FXML file in Eclipse and continue to get exceptions. Here is my main:
package application;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
static Tracker money = new Tracker(0,0,0);
static Tracker steel = new Tracker(0,0,0);
static Tracker titanium = new Tracker(0,0,0);
static Tracker plant = new Tracker(0,0,0);
static Tracker power = new Tracker(0,0,0);
static Tracker heat = new Tracker(0,0,0);
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage){
try {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("board.fxml"));
Parent root = (Parent) loader.load();
primaryStage.setScene(new Scene(root));
primaryStage.show();
} catch(NullPointerException e)
{
System.out.print("NullPointerException Caught");
e.printStackTrace();
}catch(IOException e) {
System.out.print("IOException Caught");
e.printStackTrace();
}
}
public static void nextGen() {
money.produce();
steel.produce();
titanium.produce();
plant.produce();
power.produce();
heat.produce();
}
public static void change() {
money.change();
steel.change();
titanium.change();
plant.change();
power.change();
heat.change();
}
}
I did the separate catches to see what is actually happening for Exceptions as I thought it was NullPointer at first (may still be that if a null val into the loader would give that) but the catch is happening with the IOException. I don't really know where to go from here, just would like some guidance.
EDIT
Added e.printStackTrace() per suggestion:
IOException Caughtjavafx.fxml.LoadException:
/C:/Users/pcher/eclipse-workspace/board/bin/application/board.fxml:8
at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:933)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:981)
at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:230)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:755)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
at board/application.Main.start(Main.java:27)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: application.BoardCo
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:931)
... 17 more
Here is the FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<TitledPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="Terraforming Mars Tracker" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.BoardCo">
<content>
<GridPane prefHeight="388.0" prefWidth="598.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="154.0" minHeight="154.0" prefHeight="154.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="154.0" minHeight="154.0" prefHeight="154.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="113.0" minHeight="0.0" prefHeight="41.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TitledPane animated="false" text="Money">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane layoutX="-1.0" layoutY="-2.0" prefHeight="130.0" prefWidth="194.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TextField editable="false" text="Production:" GridPane.rowIndex="1" />
<TextField editable="false" text="Change:" GridPane.rowIndex="2" />
<TextField editable="false" text="Total:" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField editable="false" GridPane.columnIndex="1" />
</children>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Steel" GridPane.columnIndex="1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane layoutY="-1.0" prefHeight="130.0" prefWidth="194.0">
<children>
<TextField editable="false" text="Production:" GridPane.rowIndex="1" />
<TextField editable="false" text="Change:" GridPane.rowIndex="2" />
<TextField editable="false" text="Total:" />
<TextField editable="false" GridPane.columnIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Titanium" GridPane.columnIndex="2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane layoutY="-1.0" prefHeight="130.0" prefWidth="194.0">
<children>
<TextField editable="false" text="Production:" GridPane.rowIndex="1" />
<TextField editable="false" text="Change:" GridPane.rowIndex="2" />
<TextField editable="false" text="Total:" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField editable="false" GridPane.columnIndex="1" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Plant" GridPane.rowIndex="1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane layoutY="-1.0" prefHeight="130.0" prefWidth="194.0">
<children>
<TextField editable="false" text="Production:" GridPane.rowIndex="1" />
<TextField editable="false" text="Change:" GridPane.rowIndex="2" />
<TextField editable="false" text="Total:" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField editable="false" GridPane.columnIndex="1" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Power" GridPane.columnIndex="1" GridPane.rowIndex="1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane layoutY="-1.0" prefHeight="130.0" prefWidth="194.0">
<children>
<TextField editable="false" text="Production:" GridPane.rowIndex="1" />
<TextField editable="false" text="Change:" GridPane.rowIndex="2" />
<TextField editable="false" text="Total:" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField editable="false" GridPane.columnIndex="1" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Heat" GridPane.columnIndex="2" GridPane.rowIndex="1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane layoutY="-1.0" prefHeight="130.0" prefWidth="194.0">
<children>
<TextField editable="false" text="Production:" GridPane.rowIndex="1" />
<TextField editable="false" text="Change:" GridPane.rowIndex="2" />
<TextField editable="false" text="Total:" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField editable="false" GridPane.columnIndex="1" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<Button mnemonicParsing="false" onAction="#btnNextGenClicked" text="Next Generation" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Button mnemonicParsing="false" onAction="#btnChangeClicked" text="Change" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</content>
</TitledPane>
And here is my controller (bare bones at the moment):
package application;
import javafx.fxml.FXML;
import javafx.event.ActionEvent;
public class BoardController {
// Event Listener on Button.onAction
@FXML
public void btnNextGenClicked(ActionEvent event) {
Main.nextGen();
}
// Event Listener on Button.onAction
@FXML
public void btnChangeClicked(ActionEvent event) {
Main.change();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
