java - Starting off with JavaFX : Can not set javafx.scene.control.Label field application.SceneController.myLabel to javafx.scene.text.Text -


i'm starting off javafx.

the error occurs when execute program, before attempted this, worked fine , button clicks worked, before intention make button click change text.

<?import javafx.scene.text.*?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.anchorpane?>  <anchorpane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.scenecontroller">    <children>       <anchorpane layoutx="-100.0" layouty="-224.0" prefheight="572.0" prefwidth="430.0">          <children>             <button layoutx="205.0" layouty="253.0" mnemonicparsing="false" onaction="#handleactionbutton1" text="do want swag?" />             <text fx:id="mylabel" layoutx="280.0" layouty="339.0" stroketype="outside" strokewidth="0.0" text="my text change!" />          </children>       </anchorpane>    </children> </anchorpane> 

that's fxml, on line, can see text "my text change!". on eclipse's fxml text editor gives me error : "you can not assign 'text' controller field 'label'".

this scenecontroller class:

package application;  import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.scene.control.label;  public class scenecontroller{      @fxml     private label mylabel;      @fxml     public void handleactionbutton1(actionevent event){         system.out.println("hello world!");         mylabel.settext("hello world!");     }  } 

as mentioned above, before had label, output "hello world" on console, that, doesn't execute java application , gives me long error:

javafx.fxml.loadexception:  /c:/users/neil/development/javafx/bin/application/appfxml.fxml:14      @ javafx.fxml.fxmlloader.constructloadexception(unknown source)     @ javafx.fxml.fxmlloader.loadimpl(unknown source)     @ javafx.fxml.fxmlloader.loadimpl(unknown source)     @ javafx.fxml.fxmlloader.load(unknown source)     @ application.main.start(main.java:15)     @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$153(unknown source)     @ com.sun.javafx.application.launcherimpl$$lambda$51/1299755900.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$runandwait$166(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$45/1051754451.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$null$164(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$47/1698159280.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.application.platformimpl.lambda$runlater$165(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$46/1775282465.run(unknown source)     @ com.sun.glass.ui.invokelaterdispatcher$future.run(unknown source)     @ com.sun.glass.ui.win.winapplication._runloop(native method)     @ com.sun.glass.ui.win.winapplication.lambda$null$141(unknown source)     @ com.sun.glass.ui.win.winapplication$$lambda$37/1109371569.run(unknown source)     @ java.lang.thread.run(unknown source) caused by: java.lang.illegalargumentexception: can not set javafx.scene.control.label field application.scenecontroller.mylabel javafx.scene.text.text     @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unknown source)     @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unknown source)     @ sun.reflect.unsafeobjectfieldaccessorimpl.set(unknown source)     @ java.lang.reflect.field.set(unknown source)     @ javafx.fxml.fxmlloader.injectfields(unknown source) 

inside fxml, have defined text, in controller, trying use label.

the stacktrace (error) shouting on top of voice :

can not set javafx.scene.control.label field application.scenecontroller.mylabel javafx.scene.text.text

in controller, need change mylabel definition to

@fxml private text mylabel; 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -