java - Starting with FXML - App returns error when changing Label ID and modifying controller accordingly -
i'm following basic tutorials. environment is: java 7 oracle sdk netbeans 7.3.1 javafx scenebuilder 1.1
i asked project wizard produce first fxml called main.
it has button on , label fx id "label". when click on it, label set "hello, world!". far good.
i want simple: add label id "label2" , add the button event in controller: label2.settext("something else");
this fails. don't understand why. details:
fxml:
<?xml version="1.0" encoding="utf-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <anchorpane id="anchorpane" prefheight="200.0" prefwidth="320.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="fs2i.maincontroller"> <children> <button id="button" layoutx="14.0" layouty="165.0" onaction="#handleclickmebuttonaction" text="say hi!" /> <label fx:id="label" layoutx="72.0" layouty="120.0" minheight="16.0" minwidth="69.0" /> <label fx:id="label2" layoutx="72.0" layouty="41.0" prefwidth="88.0" /> <button id="exit" layoutx="240.0" layouty="165.0" mnemonicparsing="false" onaction="#handleexitbuttonaction" text="exit" /> </children> </anchorpane>
controller:
/* * change template, choose tools | templates * , open template in editor. */ package fs2i; import java.net.url; import java.util.resourcebundle; import javafx.application.platform; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.label; /** * * @author nicolas */ public class maincontroller implements initializable { @fxml private label label; @fxml private label label2; @fxml private void handleclickmebuttonaction(actionevent event) { system.out.println("you clicked me!"); label.settext("hello world!"); label2.settext("something else."); } @fxml private void handleexitbuttonaction(actionevent event){ platform.exit(); } @override public void initialize(url url, resourcebundle rb) { // todo } }
what looks when click "say hi" button:
logs:
you clicked me! exception in thread "javafx application thread" java.lang.runtimeexception: java.lang.reflect.invocationtargetexception @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle(fxmlloader.java:1449)
when remove iterations of label2 in controller, works again.
something else that's odd, when initialize label2 initial text "init", not show when launch application.
i'm looking shed light on doing wrong.
Comments
Post a Comment