java - JavaFX After Splash Screen Button onClick error -


i'm making desktop application javafx , made splash screen appears 5 seconds , after 5 seconds shows new stage button, , when click button sends error:

    exception in thread "javafx application thread" java.lang.illegalargumentexception: argument type mismatch @ 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.reflect.misc.trampoline.invoke(methodutil.java:71) @ sun.reflect.generatedmethodaccessor1.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ sun.reflect.misc.methodutil.invoke(methodutil.java:275) @ javafx.fxml.fxmlloader$methodhandler.invoke(fxmlloader.java:1765) @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle(fxmlloader.java:1653) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:86) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:54) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.scene$clickgenerator.postprocess(scene.java:3471) @ javafx.scene.scene$clickgenerator.access$8100(scene.java:3399) @ javafx.scene.scene$mousehandler.process(scene.java:3767) @ javafx.scene.scene$mousehandler.access$1500(scene.java:3486) @ javafx.scene.scene.impl_processmouseevent(scene.java:1762) @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2495) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:350) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:275) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.lambda$handlemouseevent$350(glassvieweventhandler.java:385) @ com.sun.javafx.tk.quantum.glassvieweventhandler$$lambda$158/361466793.get(unknown source) @ com.sun.javafx.tk.quantum.quantumtoolkit.runwithoutrenderlock(quantumtoolkit.java:404) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(glassvieweventhandler.java:384) @ com.sun.glass.ui.view.handlemouseevent(view.java:555) @ com.sun.glass.ui.view.notifymouse(view.java:927) @ com.sun.glass.ui.win.winapplication._runloop(native method) @ com.sun.glass.ui.win.winapplication.lambda$null$145(winapplication.java:101) @ com.sun.glass.ui.win.winapplication$$lambda$36/1963387170.run(unknown source) @ java.lang.thread.run(thread.java:745) 

here javafx classes

rootform.java (splash screen)

    package forms;      import java.io.ioexception;     import java.util.logging.level;     import java.util.logging.logger;     import javafx.animation.pausetransition;     import javafx.application.application;     import javafx.fxml.fxmlloader;     import javafx.scene.parent;     import javafx.scene.scene;     import javafx.scene.image.image;     import javafx.scene.paint.color;     import javafx.stage.stage;     import javafx.stage.stagestyle;     import javafx.util.duration;       public class rootform extends application {   @override public void start(stage stage) throws exception {     parent root = fxmlloader.load(getclass().getresource("rootform.fxml"));      scene scene = new scene(root);     stage.setscene(scene);     stage.initstyle(stagestyle.transparent);     stage.show();     scene.setfill(color.transparent);     stage.geticons().add(new image("/images/8-512.png"));      pausetransition delay = new pausetransition(duration.seconds(5));     delay.setonfinished(event -> {         try {             stage mainstage = new stage();             parent parent = fxmlloader.load(getclass().getresource("error.fxml"));             mainstage.setscene(new scene(parent));             mainstage.show();             mainstage.geticons().add(new image("/images/8-512.png"));             stage.hide();         } catch (ioexception ex) {             logger.getlogger(rootform.class.getname()).log(level.severe, null, ex);         }     });     delay.play(); }  /**  * @param args command line arguments  */ public static void main(string[] args) {     launch(args); } 

}

rootform.fxml (splash screen fxml)

      <?xml version="1.0" encoding="utf-8"?>      <?import java.lang.*?>     <?import java.net.*?>     <?import java.util.*?>     <?import javafx.scene.co  ntrol.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?>  <anchorpane id="splash" maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="400.0" prefwidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">   <children>     <label layoutx="57.0" layouty="247.0" prefheight="21.0" prefwidth="202.0" text="software loading...">       <font>         <font size="15.0" />       </font>     </label>   </children>   <stylesheets>     <url value="@style.css" />   </stylesheets> </anchorpane> 

error.fxml (second stage button)

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import java.net.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?>  <anchorpane id="anchorpane"  prefheight="400.0" prefwidth="600.0" styleclass="mainfxmlclass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="forms.errorcontroller">   <children>     <button fx:id="btnmain" onmouseclicked="#btnmainactevent" layoutx="107.0" layouty="65.0" mnemonicparsing="false" prefheight="112.0" prefwidth="101.0" text="button" textfill="red" />   </children>   <stylesheets>     <url value="@style.css" />   </stylesheets> </anchorpane> 

errorcontroller.java (second stage should appear)

package forms;  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;  /**  * fxml controller class  *  * @author user  */ public class errorcontroller implements initializable {      @fxml     private button btnmain;      public void btnmainactevent(actionevent event) throws exception{          system.out.println("u shtyp!");      }     /**      * initializes controller class.      */     @override     public void initialize(url url, resourcebundle rb) {         // todo     }      } 

here screenshots: splash screen

second screen button

after click button on second screen error. can me handle this?

the problem onmouseclicked using in fxml. sends mouseevent , not actionevent.

you need use onaction in fxml in order set action performed on fire (click) event of button.

<button fx:id="btnmain" onaction="#btnmainactevent" layoutx="107.0" layouty="65.0" mnemonicparsing="false" prefheight="112.0" prefwidth="101.0" text="button" textfill="red" /> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -