java - How to fix a javafx.fxml.LoadException? -
i'm trying make javafx login window, , followed tutorial, gives me strange bug...
src/main/java/scripter/nukkit/playertool/mainapplication.java
package scripter.nukkit.playertool; import javafx.application.application; import javafx.application.platform; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.layout.stackpane; import javafx.scene.parent; import javafx.stage.stage; import javafx.fxml.*; @suppresswarnings("restriction") public class mainapplication extends application { @override public void start(stage primarystage) throws exception { parent root = fxmlloader.load(getclass().getclassloader().getresource("mainapplication.fxml")); scene scene = new scene(root, 300, 275); primarystage.settitle("fxml welcome"); primarystage.setscene(scene); primarystage.show(); } }
src/main/java/scripter/nukkit/playertool/maincontroller.java
package scripter.nukkit.playertool; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.scene.text.text; @suppresswarnings("restriction") public class maincontroller { @fxml private text actiontarget; @fxml protected void handlesubmitbuttonaction(actionevent event) { actiontarget.settext("sign in button pressed"); } }
src/main/resources/mainapplication.fxml
<?xml version="1.0" encoding="utf-8"?> <?import java.net.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> <gridpane fx:controller="scripter.nukkit.playertool.maincontroller" xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"> <padding> <insets top="25" right="25" bottom="10" left="25"/> </padding> <text text="welcome" gridpane.columnindex="0" gridpane.rowindex="0" gridpane.columnspan="2"/> <label text="user name:" gridpane.columnindex="0" gridpane.rowindex="1"/> <textfield gridpane.columnindex="1" gridpane.rowindex="1"/> <label text="password:" gridpane.columnindex="0" gridpane.rowindex="2"/> <passwordfield fx:id="passwordfield" gridpane.columnindex="1" gridpane.rowindex="2"/> <hbox spacing="10" alignment="bottom_right" gridpane.columnindex="1" gridpane.rowindex="4"> <button text="sign in" onaction="#handlesubmitbuttonaction"/> </hbox> <text fx:id="actiontarget" gridpane.columnindex="1" gridpane.rowindex="6"/> </gridpane>
error report
exception in thread "thread-7" 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) caused by: javafx.fxml.loadexception: n source) @ javafx.fxml.fxmlloader.constructloadexception(fxmlloader.java:2601) @ javafx.fxml.fxmlloader.access$700(fxmlloader.java:103) @ javafx.fxml.fxmlloader$valueelement.processattribute(fxmlloader.java:922) @ javafx.fxml.fxmlloader$instancedeclarationelement.processattribute(fxmlloader.java:971) @ javafx.fxml.fxmlloader$element.processstartelement(fxmlloader.java:220) @ javafx.fxml.fxmlloader$valueelement.processstartelement(fxmlloader.java:744) @ javafx.fxml.fxmlloader.processstartelement(fxmlloader.java:2707) @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2527) @ 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) @ scripter.nukkit.playertool.mainapplication.start(mainapplication.java:19) @ 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.classnotfoundexception: scripter.nukkit.playertool.maincontroller @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ sun.misc.launcher$appclassloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ javafx.fxml.fxmlloader$valueelement.processattribute(fxmlloader.java:920) ... 22 more
and tested
class.forname("scripter.nukkit.playertool.maincontroller")
but worked. why can't find class?!
Comments
Post a Comment