this question has answer here:
i using netbeans ide , created file using scene builder 2.0. created user interface using scene builder.
when try run application exception comes. created javafx fxml application in netbeans ide , opened fxml in scene builder , edited , after completion ran in netbeans failed desired screen.
error:
executing c:\j_progs\login\dist\run1115386562\login.jar using platform c:\program files\java\jdk1.8.0_66\jre/bin/java 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$155(launcherimpl.java:182) @ java.lang.thread.run(thread.java:745) caused by: javafx.fxml.loadexception: file:/c:/j_progs/login/dist/run1115386562/login.jar!/login/login.fxml:35 @ javafx.fxml.fxmlloader.constructloadexception(fxmlloader.java:2601) @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2579) @ 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) @ login.login.start(login.java:23) @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$162(launcherimpl.java:863) @ com.sun.javafx.application.platformimpl.lambda$runandwait$175(platformimpl.java:326) @ com.sun.javafx.application.platformimpl.lambda$null$173(platformimpl.java:295) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.application.platformimpl.lambda$runlater$174(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$148(winapplication.java:191) ... 1 more caused by: java.lang.illegalargumentexception: can not set javafx.scene.control.label field login.logincontroller.txtuser javafx.scene.control.textfield @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:167) @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:171) @ sun.reflect.unsafeobjectfieldaccessorimpl.set(unsafeobjectfieldaccessorimpl.java:81) @ java.lang.reflect.field.set(field.java:764) @ javafx.fxml.fxmlloader.injectfields(fxmlloader.java:1163) @ javafx.fxml.fxmlloader.access$1600(fxmlloader.java:103) @ javafx.fxml.fxmlloader$valueelement.processvalue(fxmlloader.java:857) @ javafx.fxml.fxmlloader$valueelement.processstartelement(fxmlloader.java:751) @ javafx.fxml.fxmlloader.processstartelement(fxmlloader.java:2707) @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2527) ... 17 more exception running application login.login
login.fxml:
<?xml version="1.0" encoding="utf-8"?> <?import javafx.scene.paint.*?> <?import javafx.scene.shape.*?> <?import javafx.scene.effect.*?> <?import javafx.scene.text.*?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <anchorpane id="anchorpane" prefheight="600.0" prefwidth="650.0" style="-fx-background-color: #dcdcdc;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="login.logincontroller"> <children> <label fx:id="lblmsg" layoutx="47.0" layouty="39.0" text="welcome" textalignment="center"> <font> <font name="system bold" size="40.0" /> </font> </label> <label layoutx="271.0" layouty="229.0" text="sign in"> <font> <font name="system bold" size="24.0" /> </font> </label> <label layoutx="130.0" layouty="300.0" text="username"> <font> <font size="15.0" /> </font> </label> <label layoutx="129.0" layouty="379.0" text="password"> <font> <font size="15.0" /> </font> </label> <textfield fx:id="txtuser" layoutx="265.0" layouty="298.0" prefheight="25.0" prefwidth="235.0" prompttext="enter username" /> <button layoutx="289.0" layouty="481.0" mnemonicparsing="false" onaction="#loginaction" opacity="0.84" style="-fx-background-color: #1e90ff;" text="sign in" textfill="white"> <font> <font size="15.0" /> </font> </button> <passwordfield fx:id="txtpass" layoutx="265.0" layouty="377.0" prefheight="25.0" prefwidth="235.0" prompttext="enter password" /> <rectangle archeight="18.0" arcwidth="18.0" fill="silver" height="174.0" layoutx="83.0" layouty="264.0" opacity="0.41" stroke="black" stroketype="inside" width="506.0" /> <rectangle archeight="12.0" arcwidth="12.0" fill="dodgerblue" height="35.0" layoutx="86.0" layouty="229.0" opacity="0.67" stroke="black" stroketype="inside" width="500.0" /> </children> </anchorpane>
logincontroller.java:
/* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package login; import java.net.url; import java.util.resourcebundle; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.label; public class logincontroller implements initializable { @fxml private label lblmsg; @fxml private label txtuser; @fxml private label txtpass; @fxml private void loginaction(actionevent event) { if(txtuser.gettext().equals("rs954") && txtpass.gettext().equals("admin")) { lblmsg.settext("welcome"); } else { lblmsg.settext("wrong credentials"); } } @override public void initialize(url location, resourcebundle resources) { throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates. } }
login.java:
/* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package login; import java.io.ioexception; import javafx.application.application; import javafx.fxml.fxmlloader; import javafx.scene.parent; import javafx.scene.scene; import javafx.stage.stage; public class login extends application { @override public void start(stage primarystage) throws ioexception { parent root = fxmlloader.load(getclass().getresource("login.fxml")); primarystage.setscene(new scene(root)); primarystage.show(); } /** * @param args command line arguments */ public static void main(string[] args) { launch(args); } }
new error:
executing c:\j_progs\login\dist\run384200010\login.jar using platform c:\program files\java\jdk1.8.0_66\jre/bin/java 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$155(launcherimpl.java:182) @ java.lang.thread.run(thread.java:745) caused by: javafx.fxml.loadexception: file:/c:/j_progs/login/dist/run384200010/login.jar!/login/login.fxml @ javafx.fxml.fxmlloader.constructloadexception(fxmlloader.java:2601) @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2579) @ 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) @ login.login.start(login.java:23) @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$162(launcherimpl.java:863) @ com.sun.javafx.application.platformimpl.lambda$runandwait$175(platformimpl.java:326) @ com.sun.javafx.application.platformimpl.lambda$null$173(platformimpl.java:295) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.application.platformimpl.lambda$runlater$174(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$148(winapplication.java:191) ... 1 more caused by: java.lang.unsupportedoperationexception: not supported yet. @ login.logincontroller.initialize(logincontroller.java:44) @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2548) ... 17 more exception running application login.login
new edit in logincontroller.java
/* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package login; import java.net.url; import java.util.resourcebundle; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.label; import javafx.scene.control.textfield; public class logincontroller implements initializable { @fxml private label lblmsg = new label(); @fxml private textfield txtuser = new textfield (); @fxml private textfield txtpass = new textfield (); @fxml private void loginaction(actionevent event) { if(txtuser.gettext().equals("rs95 4") && txtpass.gettext().equals("admin")) { lblmsg.settext("welcome"); } else { lblmsg.settext("wrong credentials"); } } @override public void initialize(url location, resourcebundle resources) { throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates. } }
txuser in fxml file textfield: <textfield fx:id="txtuser"
, in application label private label txtuser
. should use same widget in both.
Comments
Post a Comment