1

FXMLe1.java:

package fxmle1; 
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class FXMLe1 extends Application {

@Override
public void start(Stage primaryStage) throws Exception{


   Parent panel = FXMLLoader.load(getClass().getResource("FXMLe1.fxml"));        
   Scene scene = new Scene(panel, 300, 250);

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}

public static void main(String[] args) {
    launch(args);
}

}

FXMLe1.fxml:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.BorderPane?>

<GridPane fx:id="root" prefHeight="400.0" prefWidth="600.0"  xmlns:fx="http://javafx.com/fxml/1" fx:controller="fxmle1.FXMLe1Controller">
    <BorderPane>
        <top>
            <Label text = "Test Javafx"/>    
        </top>
        <center>
            <Button text = "test"/>
        </center> 
    </BorderPane>    
    <stylesheets>
       
    </stylesheets>
</GridPane>

FXMLe1Controller.java:

package fxmle1;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.Initializable;


public class FXMLe1Controller implements Initializable {

/**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
}    

}

Good Day , Everybody! So I tried to make a JavaFX project with FXML but ,unfortunatelly, i've got this problem :

Exception in Application start method
java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
 at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
 at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
 at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.FileNotFoundException: C:\Users\Амин\Documents\NetBeansProjects\JavaFX\Hehe There Is A Method To My Madness (Не удается найти указанный файл)
 at java.util.zip.ZipFile.open(Native Method)
 at java.util.zip.ZipFile.<init>(ZipFile.java:225)
 at java.util.zip.ZipFile.<init>(ZipFile.java:155)
 at java.util.jar.JarFile.<init>(JarFile.java:166)
 at java.util.jar.JarFile.<init>(JarFile.java:103)
 at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
 at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69)
 at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:94)
 at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
 at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
 at java.net.URL.openStream(URL.java:1045)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2440)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
 at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
 at fxmle1.FXMLe1.start(FXMLe1.java:29)
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
 at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
 at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
 at java.security.AccessController.doPrivileged(Native Method)
 at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
 at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
 at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
 at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
 ... 1 more
Exception running application fxmle1.FXMLe1
Java Result: 1

I tried to find solution on the Internet, but that didn't help me that much. Also I seeked for code which is making my project crush, and that is :

 Parent panel = FXMLLoader.load(getClass().getResource("FXMLe1.fxml"));

So, does someone have an answer for this?) If so, I would be glad if you told it to me.

HarvyD
  • 203
  • 1
  • 2
  • 5
  • Please, pay an attention on this line in your Ex Stack Trace: `Caused by: java.io.FileNotFoundException: C:\Users\Амин\Documents\NetBeansProjects\JavaFX\Hehe There Is A Method To My Madness (Не удается найти указанный файл)` This means that your FXML file isn't in this directory. Try to check the directory structure. Good luck, брате... – zlakad Jan 19 '18 at 05:19

1 Answers1

0

Put your FXMLe1.fxml in resources folder and then try

Parent panel = FXMLLoader.load(getClass().getResource("/FXMLe1.fxml"));

This should work as the solution for you

Black
  • 81
  • 1
  • 14
  • Excuse me, do you suggest me to create a resourses folder or to just place this file in the same folder my FXMLe.java is? – HarvyD Jan 19 '18 at 21:02
  • Its better if you create a resource folder and place that fxml file and then reference it like I said before – Black Jan 20 '18 at 15:14
  • no need to create a `resources` folder. just make sure `FXMLe1.fxml` is in your classpath. if it's in the same location as your `FXMLe.class` then you target it like so `//FXMLe1.fxml`. if it's at the root, then `/FXMLe1.fxml`. – jpllosa Mar 29 '18 at 05:18