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