java - JavaFx erron in running -


i have got problem javafx. created fxml file in scenebuilder , put in same directory package folder. here codes:

public class main  extends application    {    public static void main(string[] args){     launch(args); }     @override public void start(stage window) throws exception {     pane mainpane = (pane)fxmlloader.load(main.class.getresource("../sas.fxml"));       scene scene = new scene(mainpane);     window.setscene(scene);     window.show(); } } 

when run gives me error:

exception in application start method java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ com.sun.javafx.application.launcherimpl.launchapplicationwithargs(unknown source)     @ com.sun.javafx.application.launcherimpl.launchapplication(unknown source)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ sun.launcher.launcherhelper$fxhelper.main(unknown source) caused by: java.lang.runtimeexception: exception in application start method     @ com.sun.javafx.application.launcherimpl.launchapplication1(unknown source)     @ com.sun.javafx.application.launcherimpl.lambda$launchapplication$152(unknown source)     @ com.sun.javafx.application.launcherimpl$$lambda$50/1323468230.run(unknown source)     @ java.lang.thread.run(unknown source) caused by: javafx.fxml.loadexception:  /h:/java%20projects/javafx/bin/sas.fxml:7  @ javafx.fxml.fxmlloader.constructloadexception(unknown source) @ javafx.fxml.fxmlloader.access$700(unknown source) @ javafx.fxml.fxmlloader$valueelement.processattribute(unknown source) @ javafx.fxml.fxmlloader$instancedeclarationelement.processattribute(unknown source) @ javafx.fxml.fxmlloader$element.processstartelement(unknown source) @ javafx.fxml.fxmlloader$valueelement.processstartelement(unknown source) @ javafx.fxml.fxmlloader.processstartelement(unknown source) @ javafx.fxml.fxmlloader.loadimpl(unknown source) @ javafx.fxml.fxmlloader.loadimpl(unknown source) @ javafx.fxml.fxmlloader.loadimpl(unknown source) @ javafx.fxml.fxmlloader.loadimpl(unknown source) @ javafx.fxml.fxmlloader.loadimpl(unknown source) @ javafx.fxml.fxmlloader.loadimpl(unknown source) @ javafx.fxml.fxmlloader.loadimpl(unknown source) @ javafx.fxml.fxmlloader.load(unknown source) @ javafx.main.start(main.java:20) @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$159(unknown source) @ com.sun.javafx.application.launcherimpl$$lambda$53/1393559157.run(unknown source) @ com.sun.javafx.application.platformimpl.lambda$runandwait$172(unknown source) @ com.sun.javafx.application.platformimpl$$lambda$46/186276003.run(unknown source) @ com.sun.javafx.application.platformimpl.lambda$null$170(unknown source) @ com.sun.javafx.application.platformimpl$$lambda$48/200091476.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.application.platformimpl.lambda$runlater$171(unknown source) @ com.sun.javafx.application.platformimpl$$lambda$47/237061348.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$145(unknown source) @ com.sun.glass.ui.win.winapplication$$lambda$36/2117255219.run(unknown source) ... 1 more caused by: java.lang.classnotfoundexception: mycontroller     @ 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)     ... 28 more exception running application javafx.main 

i searched solution online, of them says problem can url. see in first code wrote (../sas.fxml) because not in same folder java files, in same folder package folder. idea how solve it? appreciate solution

fxml file

<?xml version="1.0" encoding="utf-8"?>  <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?>  <pane maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="185.0" prefwidth="349.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mycontroller">    <children>       <textfield fx:id="username" layoutx="44.0" layouty="35.0" prompttext="username" />       <button fx:id="login" layoutx="224.0" layouty="35.0" mnemonicparsing="false" onaction="#loginfucntion" text="login" />    </children> </pane> 

mycontroller.java

package javafx; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.scene.control.button; import javafx.scene.control.textfield;  public class mycontroller {      @fxml     private button login;      @fxml     private textfield username;      @fxml     void loginfucntion(actionevent event) {      }  } 

the fx:controller attribute requires fully qualified name of class. since placed mycontroller in package called javafx (which, way, shouldn't: protected package name, should choose else specific company/organization etc), need

fx:controller="javafx.mycontroller" 

since specified fx:controller="mycontroller", fxmlloader looking in default package (i.e. in root of classpath) class called mycontroller. since can't find there (it in different package), giving classnotfoundexception.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo