JavaFX - java.lang.reflect.InvocationTargetException when executing WebView exemple code - javafx

I tried to run an example of WebView project and I had this error
C:\Users\Dell\.jdks\openjdk-19.0.1\bin\java.exe "-javaagent:D:\IntelliJ IDEA 2022.2.4\lib\idea_rt.jar=50766:D:\IntelliJ IDEA 2022.2.4\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\Dell\Desktop\javafx-dialogs-0.0.4.jar;C:\Users\Dell\.m2\repository\org\icepdf\os\icepdf-viewer\6.1.2\icepdf-viewer-6.1.2.jar;C:\Users\Dell\.m2\repository\org\icepdf\os\icepdf-core\6.1.2\icepdf-core-6.1.2.jar;C:\Users\Dell\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.54\bcprov-jdk15on-1.54.jar;C:\Users\Dell\.m2\repository\org\bouncycastle\bcprov-ext-jdk15on\1.54\bcprov-ext-jdk15on-1.54.jar;C:\Users\Dell\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.54\bcpkix-jdk15on-1.54.jar;C:\Users\Dell\.m2\repository\javax\media\jai-core\1.1.3\jai-core-1.1.3.jar;C:\Users\Dell\.m2\repository\com\sun\media\jai_imageio\1.1\jai_imageio-1.1.pom;C:\Users\Dell\.m2\repository\batik\batik-awt-util\1.6\batik-awt-util-1.6.jar;C:\Users\Dell\.m2\repository\batik\batik-dom\1.6\batik-dom-1.6.jar;C:\Users\Dell\.m2\repository\batik\batik-svg-dom\1.6\batik-svg-dom-1.6.jar;C:\Users\Dell\.m2\repository\batik\batik-svggen\1.6\batik-svggen-1.6.jar;C:\Users\Dell\.m2\repository\batik\batik-util\1.6\batik-util-1.6.jar;C:\Users\Dell\.m2\repository\batik\batik-xml\1.6\batik-xml-1.6.jar;C:\Users\Dell\.m2\repository\org\jfxcore\javafx-media\18-ea+1\javafx-media-18-ea+1.jar;C:\Users\Dell\.m2\repository\org\jfxcore\javafx-graphics\18-ea+1\javafx-graphics-18-ea+1.jar;C:\Users\Dell\.m2\repository\org\jfxcore\javafx-base\18-ea+1\javafx-base-18-ea+1.jar;C:\Users\Dell\.m2\repository\org\eclipse\jetty\websocket\websocket-api\9.4.46.v20220331\websocket-api-9.4.46.v20220331.jar;C:\Users\Dell\.m2\repository\org\webjars\webjars-locator\0.30\webjars-locator-0.30.jar;C:\Users\Dell\.m2\repository\org\webjars\webjars-locator-core\0.30\webjars-locator-core-0.30.jar;C:\Users\Dell\.m2\repository\org\slf4j\slf4j-api\1.7.7\slf4j-api-1.7.7.jar;C:\Users\Dell\.m2\repository\org\apache\commons\commons-compress\1.9\commons-compress-1.9.jar;C:\Users\Dell\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.3.3\jackson-databind-2.3.3.jar;C:\Users\Dell\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.3.0\jackson-annotations-2.3.0.jar;C:\Users\Dell\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.3.3\jackson-core-2.3.3.jar;C:\Users\Dell\.m2\repository\org\apache\commons\commons-lang3\3.4\commons-lang3-3.4.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-controls\19-ea+7\javafx-controls-19-ea+7.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-graphics\19-ea+7\javafx-graphics-19-ea+7.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-base\19-ea+7\javafx-base-19-ea+7.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-fxml\19-ea+7\javafx-fxml-19-ea+7.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-web\19-ea+7\javafx-web-19-ea+7.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-media\19-ea+7\javafx-media-19-ea+7.jar;C:\Users\Dell\.m2\repository\net\synedra\validatorfx\0.3.1\validatorfx-0.3.1.jar -p "C:\Users\Dell\IdeaProjects\PFEL\target\classes;C:\Users\Dell\.m2\repository\org\openjfx\javafx-web\19-ea+7\javafx-web-19-ea+7-win.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-fxml\19-ea+7\javafx-fxml-19-ea+7-win.jar;C:\Users\Dell\.m2\repository\org\kordamp\bootstrapfx\bootstrapfx-core\0.4.0\bootstrapfx-core-0.4.0.jar;D:\MI\3LMD\memoire\Nouveau dossier\JavaFxLibs\mysql-connector-java-5.1.42-bin.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-controls\19-ea+7\javafx-controls-19-ea+7-win.jar;C:\Users\Dell\.m2\repository\org\kordamp\ikonli\ikonli-javafx\12.3.1\ikonli-javafx-12.3.1.jar;C:\Users\Dell\.m2\repository\org\kordamp\ikonli\ikonli-core\12.3.1\ikonli-core-12.3.1.jar;C:\Users\Dell\.m2\repository\org\jfxcore\javafx-graphics\18-ea+1\javafx-graphics-18-ea+1-win.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-graphics\19-ea+7\javafx-graphics-19-ea+7-win.jar;C:\Users\Dell\.m2\repository\org\jfxcore\javafx-media\18-ea+1\javafx-media-18-ea+1-win.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-media\19-ea+7\javafx-media-19-ea+7-win.jar;C:\Users\Dell\.m2\repository\com\dlsc\formsfx\formsfx-core\11.5.0\formsfx-core-11.5.0.jar;C:\Users\Dell\.m2\repository\org\jfxcore\javafx-base\18-ea+1\javafx-base-18-ea+1-win.jar;C:\Users\Dell\.m2\repository\org\openjfx\javafx-base\19-ea+7\javafx-base-19-ea+7-win.jar;C:\Users\Dell\.m2\repository\org\controlsfx\controlsfx\11.1.1\controlsfx-11.1.1.jar" -m com.example.pfel/com.example.pfel.Elearning
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: javafx.fxml.LoadException:
/C:/Users/Dell/IdeaProjects/PFEL/target/classes/com/example/pfel/Html.fxml:11
at javafx.fxml#19-ea/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
at javafx.fxml#19-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2685)
at javafx.fxml#19-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml#19-ea/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
at com.example.pfel/com.example.pfel.Elearning.start(Elearning.java:14)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics#18-ea/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:497)
at javafx.graphics#18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:470)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:469)
at javafx.graphics#18-ea/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#18-ea/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#18-ea/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:180)
... 1 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml#19-ea/javafx.fxml.JavaFXBuilderFactory$ObjectBuilderWrapper$ObjectBuilder.build(JavaFXBuilderFactory.java:237)
at javafx.fxml#19-ea/javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:774)
at javafx.fxml#19-ea/javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2924)
at javafx.fxml#19-ea/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2639)
... 12 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at javafx.fxml#19-ea/javafx.fxml.JavaFXBuilderFactory$ObjectBuilderWrapper$ObjectBuilder.build(JavaFXBuilderFactory.java:229)
... 15 more
Caused by: java.lang.NoSuchMethodError: 'void com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet()'
at javafx.controls#19-ea/javafx.scene.control.Control.<clinit>(Control.java:99)
at javafx.web#19-ea/com.sun.javafx.webkit.theme.ScrollBarThemeImpl$1.invalidated(ScrollBarThemeImpl.java:84)
at javafx.base#18-ea/com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:348)
at javafx.base#18-ea/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
at javafx.base#18-ea/javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:106)
at javafx.base#18-ea/javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:113)
at javafx.base#18-ea/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
at javafx.base#18-ea/javafx.beans.property.ObjectProperty.setValue(ObjectProperty.java:78)
at javafx.web#19-ea/javafx.scene.web.WebEngine.setView(WebEngine.java:997)
at javafx.web#19-ea/javafx.scene.web.WebView.<init>(WebView.java:276)
at javafx.web#19-ea/com.sun.javafx.fxml.builder.web.WebViewBuilder.build(WebViewBuilder.java:66)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 17 more
Exception running application com.example.pfel.Elearning
Process finished with exit code 1
and this is the fxml file and the controller
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.web.WebView?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.pfel.Html">
<children>
<WebView fx:id="webview" layoutX="6.0" layoutY="4.0" prefHeight="333.0" prefWidth="590.0" />
<Button layoutX="27.0" layoutY="361.0" mnemonicParsing="false" onAction="#loadpage" text="load" />
<TextField fx:id="textfield" layoutX="145.0" layoutY="361.0" onAction="#loadpage" />
</children>
</AnchorPane>
Controller:
package com.example.pfel;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import java.net.URL;
import java.util.ResourceBundle;
public class Html implements Initializable {
#FXML
private WebView webview;
#FXML
private TextField textfield;
private WebEngine engine;
#Override
public void initialize(URL location, ResourceBundle resources) {
engine = webview.getEngine();
loadpage();
}
public void loadpage(){
}
}

Related

JFoenix: Program throws an exception when I add a JFXProgressBar

I tried adding a JFXProgressBar component, then I get the exception below :
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1787)
at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
.... (I skipped some lines for visibility purposes)
Caused by: java.lang.IllegalAccessError: class com.jfoenix.skins.JFXProgressBarSkin (in unnamed module #0x5680343f) cannot access class com.sun.javafx.scene.NodeHelper (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.scene to unnamed module #0x5680343f
at com.jfoenix.skins.JFXProgressBarSkin.<init>(JFXProgressBarSkin.java:64)
at com.jfoenix.controls.JFXProgressBar.createDefaultSkin(JFXProgressBar.java:75)
at javafx.controls/javafx.scene.control.Control.doProcessCSS(Control.java:897)
at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Control.java:89)
at
...
When i remove the JFXProgressBar the program runs normally
I'm using javafx v14, jfoenix v9, java jdk 11.0.6.
Should i downgrade the java jdk version? or are there alternative solutions?
Minimal reproducible example:
Main.java:
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
AnchorPane root = (AnchorPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Simple.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXProgressBar?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<JFXProgressBar layoutX="200.0" layoutY="199.0" />
</children>
</AnchorPane>

javaFX-scene builder button event doesn't work

I'm trying from yesterday javaFX and scene builder in a very simple application to get button click to work, but everything I tried(by following some tutorials or related answers here) it doesn't work.
I created a new javaFX project and these are the files created with my editings:
Main.java:
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new
FXMLLoader(getClass().getResource("sample.fxml"));
loader.setController(new SampleController());
Pane root = loader.load();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource
("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
SampleControler.java:
package application;
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;
public class SampleController implements Initializable{
#FXML
Button bOk;
#FXML
Label lbTest;
private void handleButtonAction(ActionEvent event) {
// Button was clicked, do something...
lbTest.setText("Button Action\n");
}
#Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
bOk.setOnAction(this::handleButtonAction);
}
}
sample.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="220.0" prefWidth="484.0"
xmlns="http://javafx.com/javafx/8.0.111"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button id="bOk" layoutX="214.0" layoutY="152.0"
mnemonicParsing="false" text="Button" />
<Label id="lbTest" layoutX="214.0" layoutY="57.0" prefHeight="25.0"
prefWidth="138.0" text="Label" />
</children>
</Pane>
The above doesn't give any error, but when button clicked it doesn't do anything(supposed to change Label' s text).
I tried to set onAction on fxml file but this always gives error(cannot resolve onAction), no matter what I put there or if I do it from scene builder or by manually edit the fxml file(I have created the method and wrote it correct in onAction).
What I'm doing wrong?
The error I'm getting now:
javafx.fxml.LoadException:
/home/workspace/testapp/bin/application/sample.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at application.Main.start(Main.java:16)
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.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at application.SampleController.initialize(SampleController.java:27)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
After I used fx:id instead of id for button and label the button worked as expected and the above errors gone.
You forgot to use the controller with the fxml:
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="220.0" prefWidth="484.0"
xmlns="http://javafx.com/javafx/8.0.111"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.SampleController">
or
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
loader.setController(new SampleController());
Pane root = loader.load();
Furthermore you need to use fx:id instead of id attributes to inject objects to the controller:
<Button fx:id="bOk" layoutX="214.0" layoutY="152.0"
mnemonicParsing="false" text="Button" />
<Label fx:id="lbTest" layoutX="214.0" layoutY="57.0" prefHeight="25.0"
prefWidth="138.0" text="Label" />

Getting this error "at java.lang.reflect.Method.invoke(Method.java:497)" while running javafx program

I am new in javafx. I am building a basic program in javafx.
But getting error "at java.lang.reflect.Method.invoke(Method.java:497)" while running the program ...........
program is:
package myjfxapp;
import com.sun.javaws.Main;
import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class NewFXMain extends Application {
#Override
public void start(Stage primaryStage) throws IOException {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("main.fxml"));
Pane root = loader.load();
Scene scene = new Scene(root);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Fxml code:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.60">
<children>
<Button layoutX="221.0" layoutY="58.0" mnemonicParsing="false" text="Button" />
<CheckBox layoutX="211.0" layoutY="152.0" mnemonicParsing="false" text="CheckBox" />
</children>
</AnchorPane>
Stack trace:
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:497)
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)
Your help will be obliged....
You used
new FXMLLoader(Main.class.getResource(...));
and for some reason imported com.sun.javaws.Main. Your class is called NewFXMain, so you need
new FXMLLoader(NewFXMain.class.getResource(...));
or just
new FXMLLoader(getClass().getResource(...));

Cant launch application using JAVAFX FXML file

I am trying to launch the IntLogin window from the main class (MAAWB); however, I can not seem to get it to launch. My splash screen launches without issues. I ran a debug with no issues until it hits the launch sequence then it kicks back an unrecognizable error. I have included below the main, fxml and controller file. What am I missing or doing wrong here that's causing me all these headaches? Also if anyone has the answer how do I put my splash screen on a timer?
main
package javafxswingapplication3;
import javafx.application.Application;
import javafx.application.Preloader;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MAAWB extends Application {
#Override
public void start(Stage primaryStage) {
Parent root;
try {
root = FXMLLoader.load(getClass().getResource("Intlogin.fxml"));
Stage stage = new Stage();
stage.setTitle("initial login");
stage.setScene(new Scene(root, 222, 484));
stage.show();
} catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
Preloader.launch(MAAWBPreloader.class, args);
Application.launch(MAAWB.class, args);
}
}
fxml
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.effect.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="222.0" prefWidth="484.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxswingapplication3.IntloginController">
<children>
<TextField layoutX="173.0" layoutY="50.0" />
<TextField fx:id="username" editable="false" layoutX="173.0" layoutY="90.0" />
<ChoiceBox layoutX="173.0" layoutY="130.0" prefHeight="31.0" prefWidth="187.0" />
<Label layoutX="91.0" layoutY="55.0" text="Installation" />
<Label layoutX="94.0" layoutY="95.0" text="Username" />
<Label layoutX="58.0" layoutY="135.0" text="Functional Area" />
<Button cancelButton="true" layoutX="400.0" layoutY="182.0" mnemonicParsing="false" text="Cancel" />
<Button layoutX="327.0" layoutY="182.0" mnemonicParsing="false" text="Submit" />
</children>
</AnchorPane>
controller
package javafxswingapplication3;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Properties;
import static javafx.application.ConditionalFeature.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
public class IntloginController implements Initializable {
private TextField username;
#Override
public void initialize(URL url, ResourceBundle rb) {
final String UN = System.getProperty("user.name");
username.setText(UN);
}
}
error
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
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 javafxswingapplication3.MAAWB.start(MAAWB.java:31)
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)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at javafxswingapplication3.IntloginController.initialize(IntloginController.java:28)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
Annotate the username definition #FXML.
#FXML
private TextField username;
This will associate the TextField defined in your controller with the textfield defined in your FXML via fx:id="username".

JavaFX: java.lang.NullPointerException while trying to resize borderpane

Good evening guys,
I am still at the very beginning of Java programming. My current target is to resize the top of a BorderPane during the launch of the initialization. For sure, it would be very beneficial to have a separate class that contains the static constants (like the value for the size).
Unfortunately, I'm always getting a NullPointerException. I gues it's something really simple that I don't see. I hope that you can help me.
Thanks a lot in advance!
package main;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
#FXML
Pane main_top;
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("MainGui.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setMaximized(true);
BorderPane.layoutInArea(main_top, 0, 0, 200, GlobalProperties.MainGuiTopPaneHeight, 0, null, false, false, null, null, false);
} catch(Exception e) {
e.printStackTrace();
}
}
EDIT:
java.lang.NullPointerException
at javafx.scene.layout.Region.layoutInArea(Unknown Source)
at main.Main.start(Main.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/2117598489.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$44/1051754451.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1401292544.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
EDIT2 (MainGui.fxml):
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.MainGuiController">
<top>
<Pane fx:id="main_top" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #525260;" BorderPane.alignment="CENTER" />
</top>
<left>
<Pane fx:id="main_left" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #525252;" BorderPane.alignment="CENTER" />
</left>
<center>
<Pane fx:id="main_center" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</center>
<right>
<Pane fx:id="main_right" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #525252;" BorderPane.alignment="CENTER" />
</right>
<bottom>
<Pane fx:id="main_bottom" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #525260;" BorderPane.alignment="CENTER" />
</bottom>
</BorderPane>
Finally after some days of trial and error, I found a solution. Now, after it's solved it looks pretty easy ;-)
All I had to do was adding the controller initialization interface in the controller.
package main;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
public class MainGuiController implements Initializable{
//***** #author n3wton
//**** FXML declarations for MainGui.fxml
#FXML
private Pane main_top;
#FXML
private Button button1;
//***** Beginning of auto-initialized method
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
button1.setPrefSize(1, 1);
main_top.setPrefSize(50, 10);
}
}

Resources