0

I just tried to learn sth new with JavaFx... but even a "empty" JavaFX Document throws errors...

So I created a new JavaFX with FXML project. When I try to run it without changing anything i get this error:

ant -f C:\\Users\\noetz\\Documents\\NetBeansProjects\\test -Dnb.internal.action.name=run.single -Djavac.includes=test/Test.java -Drun.class=test.Test run-single
init:
deps-jar:
Created dir: C:\Users\noetz\Documents\NetBeansProjects\test\build
Updating property file: C:\Users\noetz\Documents\NetBeansProjects\test\build\built-jar.properties
Created dir: C:\Users\noetz\Documents\NetBeansProjects\test\build\classes
Created dir: C:\Users\noetz\Documents\NetBeansProjects\test\build\empty
Created dir: C:\Users\noetz\Documents\NetBeansProjects\test\build\generated-sources\ap-source-output
Compiling 1 source file to C:\Users\noetz\Documents\NetBeansProjects\test\build\classes
compile-single:
run-single:
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$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
    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 test.Test.start(Test.java:22)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
    ... 1 more
Exception running application test.Test
C:\Users\noetz\Documents\NetBeansProjects\test\nbproject\build-impl.xml:1367: The following error occurred while executing this line:
C:\Users\noetz\Documents\NetBeansProjects\test\nbproject\build-impl.xml:994: Java returned: 1
BUILD FAILED (total time: 1 second)

I can make a rightclick on the project and use clean. Then that works (but it can't be right to do that every time I use JavaFX?)

But after that its NOT possible to change the layout or add Button or anything else... It doesn't matter what I do with the scenebuilder. I can change the size by the Pane by hand and it won't change anything. So I can paste Code of my older working program in it and it simply don't change anything.

So if I just want to make sth simple like changing a label and write this

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

/**
 *
 * @author noetz
 */
public class FXMLDocumentController implements Initializable {
    
    @FXML
    private Label label;
    @FXML
    private Button btn1;
    
    private void handleButtonAction(ActionEvent event) {
        
        label.setText("Gedrückt");
    }
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    
    
}

fxml:

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

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

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/11.0.1" fx:controller="test.FXMLDocumentController">
    <children>
        <Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
      <Button fx:id="btn1" layoutX="60.0" layoutY="38.0" mnemonicParsing="false" text="Button" />
    </children>
</AnchorPane>

It still says Hello World and the Button isn't even changed. Its like its loading the standard template and i have no clue what i should do because its executing a code which isn't there... I hope someone was able to understand my poor english and could help me :'D

Lagiwer
  • 1
  • 1
  • 2
    That error means the path to the FXML file (in code you didn't show) is wrong. If it works with a a "clean and rebuild" but then doesn't work when you change the FXML file, it's likely something is misconfigured, resulting in the FXML file being deployed to the wrong place. See https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other for more information – James_D Dec 02 '20 at 19:57
  • I didnt changed it and I use the FXML file in the same Folder... The one created by Netbeans. [printscreen](https://prnt.sc/vuklly) – Lagiwer Dec 02 '20 at 20:11
  • OK, then maybe I don't understand the post. You say it works if you clean the project. And then you edit the FXML file and it doesn't work any more, and you get the stack trace posted in the question? Also, can you post the FXML file and the application class? – James_D Dec 02 '20 at 20:17
  • I posted it as a screenshot in my comment but i add it to the thread – Lagiwer Dec 02 '20 at 20:20
  • No, don't post screenshots of code (why would you even consider that?). Post it as code in your question. – James_D Dec 02 '20 at 20:21
  • No clue sry :'D – Lagiwer Dec 02 '20 at 20:23
  • I don't use NetBeans, so don't know the details of how it organizes things, but you need to look at the *build* folder and see if the FXML file is being deployed correctly, and what is in it. See the "Troubleshooting" section of the Q/A I linked. – James_D Dec 02 '20 at 20:25
  • What version of `Netbeans` are you using? Do you have `SceneBuilder` associated with `Netbeans`? Do you save your `SceneBuilder` changes before going back to `Netbeans`? – SedJ601 Dec 02 '20 at 22:09
  • When I create a project in `Netbeans`, it has a structure of `sed.work.mavenproject1.PrimaryController` in the `FXML`. You only have `test.FXMLDocumentController` in your `FXML`. – SedJ601 Dec 02 '20 at 22:12
  • Download Netbeans 12+. Follow the `Netbeans` tutorial here -> https://openjfx.io/openjfx-docs/ – SedJ601 Dec 02 '20 at 22:14
  • I have Netbeans 12.1. SceneBuilder is linked in Netbeans... i start it with doubleclick on the fxml... Yes I save it. I mean it works in Eclipse now. But I would love to use it in Netbeans... And I didnt choosed a Mavenproject? I looked it up in my old working ones and there is never sth like that you wrote with that mavenstuff :/ – Lagiwer Dec 03 '20 at 19:03

0 Answers0