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

Why is my Java Binding not working?

Controller.java: ''' package sample; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.ActionEvent; import javafx.scene.control.TextField; import javafx.fxml.FXML;

public class Controller {

@FXML
private TextField cardName;
@FXML
private TextField bAmount;


public String getmGreetText() {
    return mGreetText.getValue();
}

public StringProperty mGreetTextProperty() {
    return mGreetText;
}

public void setmGreetText(String mGreetText) {
    this.mGreetText.setValue(mGreetText);
}

private StringProperty mGreetText;

public Controller(){
    mGreetText = new SimpleStringProperty();
    setmGreetText("Hello!");

}



public void setICardName(ActionEvent actionEvent) {
    System.out.printf("Card Named: %s With amount: %s %n", cardName.getText(), bAmount.getText());
}

}

'''

fxml file:

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

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

<GridPane fx:id="hScene" alignment="center" stylesheets="/css/style.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">

<Text text="${controller.mGreetText}" styleClass="mGreeting"GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="0" />

<Label styleClass="gLabel" text="Budget-Card Name: " GridPane.columnIndex="0" GridPane.rowIndex="1" />

<TextField styleClass="gTField" fx:id="cardName" GridPane.columnIndex="1" GridPane.rowIndex="1" />

<Label styleClass="gLabel" text="Budget Amount: " GridPane.columnIndex="0" GridPane.rowIndex="2" />

<TextField styleClass="gTField" fx:id="bAmount" GridPane.columnIndex="1" GridPane.rowIndex="2" />

<Button fx:id="scButton" styleClass="mButton" onAction="#setICardName" prefHeight="29.0" prefWidth="168.0" text="+ Add Card" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="3" />

</GridPane>

''' Main file: ''' package sample;

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 {

@Override
public void start(Stage primaryStage) throws Exception{

    Parent root = FXMLLoader.load(getClass().getResource("/fxml/sample.fxml"));
    primaryStage.setTitle("Budget Buddy | Desktop Edition");
    primaryStage.setScene(new Scene(root, 375, 475));
    primaryStage.setResizable(false);
    primaryStage.show();
}


public static void main(String[] args) {
    launch(args);
}

}

''' Error: ''' "C:\Program Files\Java\jdk1.8.0_111\bin\java" -Didea.launcher.port=7544 "-Didea.launcher.bin.path=C:\Users\busti\IntelliJ IDEA Community Edition 2016.3.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_111\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\rt.jar;C:\Users\busti\IdeaProjects\BudgetBuddy\out\production\BudgetBuddy;C:\Users\busti\IntelliJ IDEA Community Edition 2016.3.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain sample.Main Exception in Application start method Exception in thread "main" java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745) Caused by: javafx.fxml.LoadException: /C:/Users/busti/IdeaProjects/BudgetBuddy/out/production/BudgetBuddy/fxml/sample.fxml:11

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2543)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at sample.Main.start(Main.java:15)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more

Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[11,65] Message: Element type "Text" must be followed by either attribute specifications, ">" or "/>". at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596) at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:88) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2513) ... 17 more

Process finished with exit code 1

'''