Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

"Exception in Application start method"-error in loading fxml Button nodes.

I get an error in my main.java loading this line:

Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));

Through commenting them out and having it work, I have traved the issue to my Button nodes, but I can't figure out why.

An example of one of my buttons:

<Button GridPane.rowIndex="1" GridPane.columnIndex="2" OnAction="#handleBuyBlue" text="Buy"/>

Here is my full fxml document. I have four buttons total: they're currently commented out.

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.text.Text?>



<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
    <Text text="Trim the Hedge" styleClass="title" GridPane.rowIndex="0" GridPane.columnSpan="2" GridPane.halignment="CENTER"/>
    <Text text="Profit Margin" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
    <Label text="0" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
    <!--<Button GridPane.rowIndex="1" GridPane.columnIndex="2" OnAction="#handleBuyBlue" text="Buy"/>-->
    <Text text="Total Employees" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
    <Label text="F" GridPane.rowIndex="2" GridPane.columnIndex="1"/>

    <Text text="FT Employees w/ Benefits" GridPane.rowIndex="3" GridPane.columnIndex="0"/>
    <Label text="0" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
    <!--<Button GridPane.rowIndex="2" GridPane.columnIndex="2" OnAction="#handleFireOneFTBlue" text="fire 1 FT"/>-->

    <Text text="PT Employees" GridPane.rowIndex="4" GridPane.columnIndex="0"/>
    <Label text="0" GridPane.rowIndex="4" GridPane.columnIndex="1"/>
    <!--<Button GridPane.rowIndex="4" GridPane.columnIndex="2" OnAction="#handleFireOnePTBlue" text="fire 1 PT"/>-->

    <Text text="Sub-contracted employed" GridPane.rowIndex="5" GridPane.columnIndex="0"/>
    <Label text="0" GridPane.rowIndex="5" GridPane.columnIndex="1"/>
    <!--<Button GridPane.rowIndex="4" GridPane.columnIndex="2" OnAction="#handleFireOneSCBlue" text="fire 1 SC"/>-->

    <Text text="Lives Ruined" GridPane.rowIndex="6" GridPane.columnIndex="0"/>
    <Label text="F" GridPane.rowIndex="6" GridPane.columnIndex="1"/>



</GridPane>

1 Answer

I realized the problem was a camelCase error. It's "onAction" instead of "OnAction."

<Button GridPane.rowIndex="1" GridPane.columnIndex="2" onAction="#handleBuyBlue" text="Buy"/>