java - Error loading fxml file in a JavaFX project -


i have been working on desktop application, need use javafx. have created fxml file in javafx project on eclipse. build scene in scene builder.when trying run main java file, changes made using scene builder on fxml file not getting reflected on main window.and screen displayed blank. here code.

public class main extends application { @override public void start(stage primarystage) {     try {         anchorpane  root = new anchorpane();          scene scene = new scene(root,400,400,color.black);         scene.getstylesheets().add(getclass().getresource("/application/sample.fxml").getpath());         primarystage.settitle("fxml welcome");          primarystage.setscene(scene);         primarystage.show();     } catch(exception e) {         e.printstacktrace();     } }  public static void main(string[] args) {     launch(args); } 

and sample.fxml file code:

<?xml version="1.0" encoding="utf-8"?> <?import java.lang.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.anchorpane?> <?scenebuilder-background-color 0x00ffa3ff?>  <anchorpane prefheight="379.0" prefwidth="549.0001220703125" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">  <children> <button layoutx="219.0" layouty="156.0" mnemonicparsing="false" text="hello" /> </children> </anchorpane> 

the error got was:

     warning: com.sun.javafx.css.stylemanager loadstylesheetunprivileged resource "/f:/eclipse_progs/examplefx/bin/application/sample.fxml" not found. 

but location in error specified contains file referring to. can explain might reason error. code or issues of plugin?

in javafx, if want load fxml file, use fxmlloader as,

fxmlloader.load(getclass().getresource("application/sample.fxml")); 

to load stylesheet use as.

scene.getstlyeshees().add(getclass().getresource("application/sample.css").toexternalform); 

in code, adding fxml file in stylesheets list of scene wrong. try using fxmlloader said above load fxml file.

refer docs: http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -