java - JavaFX Controller not defined in root element -


i'm new javafx, i'm using scenebuilder,it's supposed display text area, button , list. have controller class :

    package gui;      import java.net.url;     import java.util.resourcebundle;     import javafx.event.actionevent;     import javafx.fxml.fxml;     import javafx.fxml.initializable;     import javafx.scene.control.button;     import javafx.scene.control.listview;     import javafx.scene.control.textarea;          public class commentairecontroller implements initializable {              /**              * initializes controller class.              */             @override             public void initialize(url url, resourcebundle rb) {                 // todo             }                    @fxml             private listview lvcom;               @fxml             private text  area txtacom;         @fxml         private button buttoncom;             @fxml            private void buttoncomonaction (actionevent event)            {               txtacom.settext("test");            }        } 

and fxml file :

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?>  <anchorpane id="anchorpane" maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="400.0" prefwidth="600.0" style="&#10;  -fx-background-color:&#9;#c0c0c0;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">   <children>     <textarea fx:id="actiontarget" depthtest="inherit" layoutx="14.0" layouty="319.0" prefheight="60.0" prefwidth="403.0" wraptext="true" />     <listview layoutx="10.0" layouty="14.0" prefheight="272.0" prefwidth="579.0000999999975" />     <scrollbar layoutx="573.0" layouty="14.0" orientation="vertical" prefheight="272.0" />     <button fx:id="buttoncom" layoutx="428.0" layouty="326.0" mnemonicparsing="false" onaction="buttoncomonaction" prefheight="46.0" prefwidth="161.0" text="commenter" textfill="#152020">       <font>         <font name="aharoni bold" size="15.0" />       </font>     </button>   </children> </anchorpane> 

when run project exception log :

exception in application start method java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ com.sun.javafx.application.launcherimpl.launchapplicationwithargs(launcherimpl.java:389)     @ com.sun.javafx.application.launcherimpl.launchapplication(launcherimpl.java:328)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:497)     @ sun.launcher.launcherhelper$fxhelper.main(launcherhelper.java:767) caused by: java.lang.runtimeexception: exception in application start method     @ com.sun.javafx.application.launcherimpl.launchapplication1(launcherimpl.java:917)     @ com.sun.javafx.application.launcherimpl.lambda$launchapplication$156(launcherimpl.java:182)     @ java.lang.thread.run(thread.java:745) caused by: javafx.fxml.loadexception: error resolving onaction='buttoncomonaction', either event handler not in namespace or there error in script. /c:/users/hadhe/documents/netbeansprojects/crowdrisee/build/classes/gui/commentaire.fxml:19      @ javafx.fxml.fxmlloader.constructloadexception(fxmlloader.java:2597)     @ javafx.fxml.fxmlloader.access$100(fxmlloader.java:103)     @ javafx.fxml.fxmlloader$element.processeventhandlerattributes(fxmlloader.java:610)     @ javafx.fxml.fxmlloader$valueelement.processendelement(fxmlloader.java:770)     @ javafx.fxml.fxmlloader.processendelement(fxmlloader.java:2823)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2532)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2441)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3214)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3175)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3148)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3124)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3104)     @ javafx.fxml.fxmlloader.load(fxmlloader.java:3097)     @ gui.main.start(main.java:24)     @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$163(launcherimpl.java:863)     @ com.sun.javafx.application.platformimpl.lambda$runandwait$176(platformimpl.java:326)     @ com.sun.javafx.application.platformimpl.lambda$null$174(platformimpl.java:295)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.application.platformimpl.lambda$runlater$175(platformimpl.java:294)     @ com.sun.glass.ui.invokelaterdispatcher$future.run(invokelaterdispatcher.java:95)     @ com.sun.glass.ui.win.winapplication._runloop(native method)     @ com.sun.glass.ui.win.winapplication.lambda$null$149(winapplication.java:191)     ... 1 more exception running application gui.main c:\users\hadhe\documents\netbeansprojects\crowdrisee\nbproject\build-impl.xml:1039: following error occurred while executing line: c:\users\hadhe\documents\netbeansprojects\crowdrisee\nbproject\build-impl.xml:804: java returned: 1 build failed (total time: 3 seconds) 

any possible solutions?

try changing:

onaction="buttoncomonaction" 

to

onaction="#buttoncomonaction" 

in button's element within fxml layout.

plus, need specify handler controller on root element:

<anchorpane fx:controller="gui.commentairecontroller" ... 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -