Here's my project on the Secrets app(I'm trying to build the login/signup page, but this blocks my way!). The error code is pasted after it. Thanks!
Main.java -
package com.example.secret;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
#Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("main.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Main.fxml -
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.Blend?>
<?import javafx.scene.effect.Glow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox alignment="CENTER" prefHeight="692.0" prefWidth="868.0" spacing="20.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/16" fx:controller="com.example.secret.MainController">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<children>
<Label text="Secret Vault!" textAlignment="CENTER" textFill="#0066ff">
<font>
<Font name="MV Boli" size="48.0" />
</font>
<effect>
<Blend mode="SOFT_LIGHT">
<topInput>
<Glow level="0.62" />
</topInput>
</Blend>
</effect>
</Label>
<HBox prefHeight="673.0" prefWidth="828.0">
<AnchorPane prefHeight="558.0" prefWidth="225.0">
<ImageView fitHeight="89.0" fitWidth="150.0" layoutX="101.0" layoutY="14.0" pickOnBounds="true"
preserveRatio="true">
<image>
<Image url="#Image/secure-blue-icon.png"/>
</image>
</ImageView>
<AnchorPane layoutY="122.0" prefHeight="436.0" prefWidth="200.0">
<Label layoutX="8.0" prefHeight="60.0" prefWidth="282.0" text="Your secrets, in your vault,"
textFill="#0066ff">
<font>
<Font name="Ink Free" size="24.0"/>
</font>
<effect>
<Blend mode="SOFT_LIGHT">
<topInput>
<Glow level="0.62"/>
</topInput>
</Blend>
</effect>
</Label>
<Label layoutX="63.0" layoutY="38.0" prefHeight="60.0" prefWidth="164.0"
text="saved securely!" textFill="#0066ff">
<font>
<Font name="Ink Free" size="24.0"/>
</font>
<effect>
<Blend mode="SOFT_LIGHT">
<topInput>
<Glow level="0.62"/>
</topInput>
</Blend>
</effect>
</Label>
<ImageView fitHeight="89.0" fitWidth="153.0" layoutX="100.0" layoutY="98.0"
pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#Image/blue-key-icon.png"/>
</image>
</ImageView>
<Label layoutX="57.0" layoutY="196.0" prefHeight="60.0" prefWidth="184.0"
text="Who has the key?" textFill="#0066ff">
<font>
<Font name="Ink Free" size="24.0"/>
</font>
<effect>
<Blend mode="SOFT_LIGHT">
<topInput>
<Glow level="0.62"/>
</topInput>
</Blend>
</effect>
</Label>
<Label layoutX="75.0" layoutY="233.0" prefHeight="60.0" prefWidth="149.0"
text="YOU, yes, only!" textFill="#0066ff">
<font>
<Font name="Ink Free" size="24.0"/>
</font>
<effect>
<Blend mode="SOFT_LIGHT">
<topInput>
<Glow level="0.62"/>
</topInput>
</Blend>
</effect>
</Label>
<Button layoutX="86.0" layoutY="315.0" mnemonicParsing="false" text="Animate" fx:id="button-animate">
<font>
<Font name="Cambria" size="24.0"/>
</font>
</Button>
</AnchorPane>
</AnchorPane>
</HBox>
</children>
</VBox>
Error -
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: javafx.fxml.LoadException: Invalid identifier.
/C:/Users/{myname}/Desktop/Netbrain%20IDE%20Projects/Secret/target/classes/com/example/secret/main.fxml:99
at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2703)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:911)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:982)
at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:229)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2517)
at com.example.secret/com.example.secret.Main.start(Main.java:14)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:474)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application com.example.secret.Main
Thanks for you help! I know what it's like to be stuck on a error, but maybe I shouls start helping people because I mostly ask, ask ask!
The stack trace tells you that there is a problem in line 99 of file main.fxml.
/C:/Users/{myname}/Desktop/Netbrain%20IDE%20Projects/Secret/target/classes/com/example/secret/main.fxml:99
I believe that means the following line:
<Button layoutX="86.0" layoutY="315.0" mnemonicParsing="false" text="Animate" fx:id="button-animate">
The value for attribute fx:id is button-animate. The hyphen (or dash) character, i.e. -, is not a valid character for java identifiers. This is also mentioned in the following line from the stack trace.
Caused by: javafx.fxml.LoadException: Invalid identifier
Maybe you should consider using java naming conventions.
In any case, the stack trace is your friend. You need to learn how to read and interpret it.
Related
I'm new in java, so I have to ask you for help :P.
I'm creating very simple program, but I stucked on verifying password and login textField. I'm wondering what is wrong with that code, can you help me?
Controller
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;
import java.awt.*;
public class Controller {
#FXML
public TextField login,password;
public void LoginButtonClicked(ActionEvent event)
{
if(login.getText().equals("yes")&&password.getText().equals("yes"))
{
System.out.print("Congratulations");
}
else
{
System.out.print("no");
}
}
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<top>
<VBox BorderPane.alignment="CENTER">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="Profile">
<items>
<MenuItem mnemonicParsing="false" text="Your Profile" />
<MenuItem mnemonicParsing="false" text="Log out" />
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About program" />
<MenuItem mnemonicParsing="false" text="Author" />
</items>
</Menu>
</menus>
</MenuBar>
<HBox spacing="8.0">
<children>
<TextField fx:id="login" promptText="User" /> // ERROR
<TextField fx:id="password" layoutX="10.0" layoutY="10.0" promptText="Password" /> //ERROR
<Region HBox.hgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="#LoginButtonClicked" text="Log In" />
<Button layoutX="329.0" layoutY="15.0" mnemonicParsing="false" text="Clear" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</HBox>
</children>
</VBox>
</top>
<center>
<Label alignment="CENTER" prefHeight="130.0" prefWidth="469.0" text="Log in, in order to use this program" BorderPane.alignment="CENTER">
<font>
<Font size="25.0" />
</font>
</Label>
</center>
</BorderPane>
And the error code
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$1/868693306.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
/C:/Users/Michael/IdeaProjects/Endomondo/out/production/Endomondo/sample/sample.fxml:36
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2573)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3208)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
at sample.Main.start(Main.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/1482523563.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1674404664.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/992465164.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/668291877.run(Unknown Source)
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$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/1584193862.run(Unknown Source)
... 1 more
Caused by: java.lang.IllegalArgumentException: Can not set java.awt.TextField field sample.Controller.login to javafx.scene.control.TextField
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:758)
at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1155)
at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:853)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:747)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
... 22 more
Your problem is in import in Controller class:
import java.awt.*;
Should be:
import javafx.scene.control.TextField;
The programs tries to convert java.awt.TextField to javafx.scene.control.TextField
I assume you'd like to use javafx, not AWT TextField
Note: don't trust the imports which IDE gives you :)
Check imports, sometimes the IDE will suggest you to import the AWT but since we work with JAVAFX we need to import controls with help of javafx.scene.control.;
This question already has an answer here:
javaFX program not working after changing the scene builder and jdk
(1 answer)
Closed 4 months ago.
I am new to javafx.Currently I am developing a miniproject.I am designing it's UI in scene builder-18.0.0.
I have added fontawesomefx jar file to reference library.
When I use fontawesomefx icons to my project, it's shows the following Exception.If I remove the icons, the program runs fine.
Result
Exception in Application start method
java.lang.reflect.InvocationTargetExceptionf
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at javafx.graphics#18.0.2/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics#18.0.2/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:577)
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.0.2/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics#18.0.2/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/parser/CSSParser
at de.jensd.fx.glyphs.GlyphIcon.<clinit>(GlyphIcon.java:49)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1160)
at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.ensureClassInitialized(MethodHandleAccessorFactory.java:300)
at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newConstructorAccessor(MethodHandleAccessorFactory.java:103)
at java.base/jdk.internal.reflect.ReflectionFactory.newConstructorAccessor(ReflectionFactory.java:236)
at java.base/java.lang.reflect.Constructor.acquireConstructorAccessor(Constructor.java:546)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:496)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
at javafx.fxml#18.0.2/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1020)
at javafx.fxml#18.0.2/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:757)
at javafx.fxml#18.0.2/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
at javafx.fxml#18.0.2/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
at javafx.fxml#18.0.2/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml#18.0.2/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
at App.start(App.java:19)
at javafx.graphics#18.0.2/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics#18.0.2/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics#18.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#18.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics#18.0.2/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#18.0.2/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#18.0.2/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.parser.CSSParser
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 25 more
Exception running application App
My Fxml code
<?xml version="1.0" encoding="UTF-8"?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="609.0" prefWidth="932.0" styleClass="holder" stylesheets="#TableStyle.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Pane layoutY="7.0" prefHeight="28.0" prefWidth="932.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label layoutX="17.75" layoutY="3.0" styleClass="app-title" text="Hello Tables" textFill="WHITE">
<font>
<Font size="15.0" />
</font>
</Label>
</children>
</Pane>
<AnchorPane layoutX="14.0" layoutY="28.0" prefHeight="200.0" prefWidth="256.0" styleClass="sideview" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="7.0" AnchorPane.topAnchor="28.0">
<children>
<StackPane alignment="CENTER_RIGHT" layoutX="17.0" layoutY="48.0" AnchorPane.leftAnchor="35.6" AnchorPane.topAnchor="45.0">
<children>
<TextField promptText="Search here" styleClass="txt-field" />
</children>
</StackPane>
<ListView layoutX="28.0" layoutY="131.0" prefHeight="200.0" prefWidth="200.0" styleClass="listview" AnchorPane.bottomAnchor="110.0" AnchorPane.topAnchor="125.0" />
<StackPane layoutX="17.0" layoutY="514.0" prefHeight="30.0" prefWidth="222.0" AnchorPane.bottomAnchor="29.600000000000023">
<children>
<Button maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" prefHeight="30.0" prefWidth="145.0" styleClass="btn-new-table" />
<Label styleClass="txt-new-table" text="NEW TABLE" />
</children>
</StackPane>
<FontAwesomeIconView layoutX="111.0" layoutY="293.0" />
</children>
</AnchorPane>
<AnchorPane layoutX="316.0" layoutY="38.0" prefHeight="200.0" prefWidth="200.0" styleClass="sideview" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="267.0" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="28.0">
<children>
<Label layoutX="27.0" layoutY="69.0" text="NOTES" AnchorPane.leftAnchor="27.0" AnchorPane.topAnchor="69.0">
<font>
<Font name="System Bold" size="21.0" />
</font>
</Label>
<StackPane layoutX="27.0" layoutY="126.0" prefHeight="353.0" prefWidth="611.0" AnchorPane.bottomAnchor="96.0" AnchorPane.leftAnchor="27.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="125.0">
<children>
<Label alignment="TOP_LEFT" prefHeight="75.0" prefWidth="214.0" styleClass="txt-no-table" text="NO TABLE SELECTED" textAlignment="CENTER" StackPane.alignment="CENTER">
<font>
<Font name="Roboto" size="16.799999237060547" />
</font>
</Label>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Pane layoutY="41.0" prefHeight="200.0" prefWidth="200.0" styleClass="table-holder" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="106.5" AnchorPane.topAnchor="2.0" />
<TableView prefHeight="353.0" prefWidth="503.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="95.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn prefWidth="75.0" text="NAME" />
<TableColumn prefWidth="75.0" text="AGE" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<VBox alignment="CENTER" layoutX="556.0" layoutY="27.0" prefHeight="327.0" prefWidth="48.0" AnchorPane.bottomAnchor="27.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="0.0">
<children>
<FlowPane alignment="CENTER" orientation="VERTICAL" prefHeight="315.0" prefWidth="55.0" styleClass="toolbar" />
</children>
</VBox>
</children>
</AnchorPane>
</children></StackPane>
<FlowPane alignment="CENTER_LEFT" hgap="10.0" layoutX="27.0" layoutY="432.0" prefHeight="102.0" prefWidth="490.0" vgap="10.0" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="27.0" AnchorPane.rightAnchor="141.0">
<children>
<TextField promptText="Search here" styleClass="txt-field" />
</children>
</FlowPane>
<StackPane layoutX="422.0" layoutY="499.0" maxHeight="-Infinity" prefHeight="30.0" prefWidth="153.0" AnchorPane.bottomAnchor="30.0" AnchorPane.rightAnchor="120.0">
<children>
<Button maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" prefHeight="30.0" prefWidth="131.0" styleClass="btn-new-table" />
<Label styleClass="txt-new-table" text="ADD ROW" />
</children>
</StackPane>
</children>
</AnchorPane>
</children>
</AnchorPane>
Java(Main class)
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class App extends Application{
#Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("TableAppInterface.fxml"));
System.out.println("hi");
Parent root = null;
try {
root = loader.load();
} catch (IOException e) {
e.printStackTrace();
}
Scene scene = new Scene(root);
stage.setScene(scene);
//stage.initStyle(StageStyle.TRANSPARENT);
stage.setTitle("Tables");
stage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Launch App",
"request": "launch",
"mainClass": "App",
"projectName": "TableApp_e71931e0",
"vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-18.0.2/lib\" --add-modules javafx.controls,javafx.fxml"
}
]
}
I also tried with the following vmArgs
"vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-18.0.2/lib\" --add-modules javafx.controls,javafx.fxml \ --add-opens javafx.graphics/javafx.css=ALL-UNNAMED"
I also visited this post and used fontawesomfx 8.4.but it didn't work.It shows the same exception.
Currently I am using java 18(jdk-18.0.2) and javafx-sdk-18.0.2 and SceneBuilder-18.0.0 and fontawesomefx 8.9 jar.I use visual studio code.I am not using any built tools for my project.
NOTE:If I run the code without any fontawesomefx icons, my code works fine.
I have been searching the solution for this problem for an entire day.Please explain me what is the problem and how to solve it.I want to use fontawesomeicons in my project.How to do it?
Thank you
You need to upgrade the version of fontawesomefx you are using to be compatible with your java version.
See the answer to this question, I believe your problem is the same as this person was seeing.
This is my fx class
package application;
import java.io.File;
import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("as1.fxml"));
primaryStage.setTitle("Abdul-Rahim University");
primaryStage.setScene(new Scene(root, 800, 500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
and this is as1.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.effect.GaussianBlur?>
<?import javafx.scene.effect.MotionBlur?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="abd">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="New" />
<MenuItem mnemonicParsing="false" text="Open…" />
<Menu mnemonicParsing="false" text="Open Recent" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Close" />
<MenuItem mnemonicParsing="false" text="Save" />
<MenuItem mnemonicParsing="false" text="Save As…" />
<MenuItem mnemonicParsing="false" text="Revert" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Preferences…" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Undo" />
<MenuItem mnemonicParsing="false" text="Redo" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Cut" />
<MenuItem mnemonicParsing="false" text="Copy" />
<MenuItem mnemonicParsing="false" text="Paste" />
<MenuItem mnemonicParsing="false" text="Delete" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Select All" />
<MenuItem mnemonicParsing="false" text="Unselect All" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About MyHelloApp" />
</items>
</Menu>
</menus>
</MenuBar>
<AnchorPane fx:id="ar" maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<children>
<BorderPane fx:id="bo" layoutX="69.0" layoutY="32.0" prefHeight="200.0" prefWidth="200.0" />
<HBox fx:id="hb" focusTraversable="true" layoutX="70.0" layoutY="128.0" prefHeight="100.0" prefWidth="420.0" spacing="10.0">
<children>
<Button fx:id="st" mnemonicParsing="false" onAction="#handleButtonAction" text="Students" />
<Button fx:id="ac" mnemonicParsing="false" onAction="#handleButtonAction2" text="Academics" />
<Button fx:id="co" mnemonicParsing="false" onAction="#handleButtonAction3" text="Courses" />
</children>
<opaqueInsets>
<Insets bottom="11.0" left="11.0" right="11.0" top="10.0" />
</opaqueInsets>
<effect>
<GaussianBlur radius="1.75" />
</effect>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<Label fx:id="l1" contentDisplay="BOTTOM" layoutX="236.0" layoutY="26.0" text="University" textAlignment="CENTER" textOverrun="WORD_ELLIPSIS">
<font>
<Font name="Dubai Regular" size="33.0" />
</font>
<effect>
<MotionBlur radius="5.5" />
</effect>
</Label>
</children>
</AnchorPane>
</children>
</VBox>
I have tried to solve it alot and i cant if anyone can help me please solve this problem to me Exception running application applicatio i have tried to solve it alot and i cant if anyone can help me please solve this problem to me Exception running application applicatio
eclipse
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source) 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(Unknown Source) Caused by: javafx.fxml.LoadException:
/C:/Users/Abdurrahim/Desktop/mamoun/GUI/bin/application/as1.fxml:18
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:922)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
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 application.Main.start(Main.java:18)
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
Caused by: java.lang.ClassNotFoundException: abd
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:920)
... 22 more Exception running application application.Main
my controller
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
public class FXMLDocumentController {
#FXML
private AnchorPane ar;
#FXML
private BorderPane bo;
#FXML
private HBox hb;
#FXML
private Button st;
#FXML
private Button ac;
#FXML
private Button co;
#FXML
private Label l1;
#FXML
void handleButtonAction(ActionEvent event) {
System.out.println("abd");
}
#FXML
void handleButtonAction2(ActionEvent event) {
System.out.println("abd");
}
#FXML
void handleButtonAction3(ActionEvent event) {
System.out.println("abd");
}
}
javafx
Here is the solution: fx:controller="application.FXMLDocumentController"
I have a project with 2 windows, the first one pass parameter to the second, but when running the project, the main class doesn't lunch the window, instead I've got this exception:
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 tic_tac_toe.TIC_TAC_TOE.start(TIC_TAC_TOE.java:21)
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)
here is my main code:
#Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Choices.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Tic Tac Toe");
primaryStage.getIcons().add(new Image("img/icon.png"));
primaryStage.setResizable(false);
primaryStage.show();
}
I've read all the posts about InvocationTargetException but it seems not the same problem, I can't understand where is the error, I've the same code on another project and it works (sorry I'm neww with javaFx, it's just my second project).
here is the FXML file:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXRadioButton?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="266.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tic_tac_toe.ChoicesController">
<children>
<BorderPane prefHeight="258.0" prefWidth="600.0" AnchorPane.bottomAnchor="51.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<Pane prefHeight="100.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<Label layoutX="170.0" layoutY="23.0" prefHeight="50.0" prefWidth="344.0" text="Veuiller choisr un mode de jeux :">
<font>
<Font size="18.0" />
</font>
</Label>
<ImageView fitHeight="78.0" fitWidth="81.0" layoutX="70.0" layoutY="10.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../img/question-speech-bubble.png" />
</image>
</ImageView>
</children>
</Pane>
</top>
<center>
<Pane prefHeight="97.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<VBox layoutX="29.0" layoutY="8.0" prefHeight="80.0" prefWidth="549.0">
<children>
<JFXRadioButton fx:id="rdJoueur" prefHeight="50.0" text="Un joueur avec une machine">
<font>
<Font size="18.0" />
</font>
</JFXRadioButton>
<JFXRadioButton fx:id="rdMachine" prefHeight="50.0" text="Deux machines">
<font>
<Font size="18.0" />
</font>
</JFXRadioButton>
</children>
</VBox>
</children>
</Pane>
</center>
</BorderPane>
<Pane layoutX="-3.0" layoutY="198.0" prefHeight="58.0" prefWidth="600.0">
<children>
<JFXButton fx:id="btnOk" buttonType="RAISED" layoutX="479.0" layoutY="15.0" prefHeight="35.0" prefWidth="100.0" ripplerFill="#ffffff00" style="-fx-background-color: #2196f3;" text="Valider" textFill="WHITE">
<font>
<Font size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnCancel" buttonType="RAISED" layoutX="360.0" layoutY="15.0" prefHeight="35.0" prefWidth="100.0" ripplerFill="#ffffff00" style="-fx-background-color: #2196f3;" text="Annuler" textFill="WHITE">
<font>
<Font size="14.0" />
</font>
</JFXButton>
</children>
</Pane>
</children>
</AnchorPane>
Thanks
Comment out //
//primaryStage.getIcons().add(new Image("img/icon.png"));
I'm new to javafx and i was trying to make a gui from which when a button is clicked, it would go to another window. I tried reading many answers found on Stack Overflow. I even tried making the project again from the beginning...But i keep on getting the same error.
That is Exception is Application start method
java.lang.reflect.InvocationTargetException javafx
My Main
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class SkyTravelsFx extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Login.fxml"));
stage.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
LoginController.java
package skytravelsfx;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class LoginController implements Initializable {
#FXML
TextField username;
#FXML
TextField password;
#FXML
Button user;
#FXML
Button admin;
#FXML
Button login;
#FXML
public void btnClicked (ActionEvent actionEvent){
try{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("User.fxml"));
Parent root=(Parent) fxmlLoader.load();
Stage stage = new Stage();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
((Stage)(((Button)actionEvent.getSource()).getScene().getWindow())).hide();
}catch(Exception e){
e.printStackTrace();
}
}
#Override
public void initialize(URL location, ResourceBundle resources) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Please note that i still haven't written any codes in UserController.java
I just made the ui for User.fxml
Login.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="766.0" prefWidth="1366.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="skytravelsfx.LoginController">
<children>
<ImageView fitHeight="866.0" fitWidth="1397.0" layoutX="10.0" layoutY="11.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../../SkyTravelFx/src/goodwp.com_25168.jpg" />
</image>
</ImageView>
<Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
<Label fx:id="label1" layoutX="565.0" layoutY="517.0" minHeight="16" minWidth="69" text="Select User">
<font>
<Font size="18.0" />
</font>
</Label>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#095a77" height="140.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="1386.0" />
<Label fx:id="label11" layoutX="56.0" layoutY="33.0" minHeight="16" minWidth="69" text="Sky Travels" textFill="WHITE">
<font>
<Font name="System Italic" size="72.0" />
</font>
</Label>
<Label fx:id="label12" layoutX="432.0" layoutY="91.0" minHeight="16" minWidth="69" text="Making your destination closer..." textFill="WHITE">
<font>
<Font name="System Italic" size="18.0" />
</font>
</Label>
<AnchorPane layoutX="83.0" layoutY="252.0" prefHeight="507.0" prefWidth="383.0">
<children>
<ImageView fitHeight="191.0" fitWidth="234.0" layoutX="96.0" layoutY="6.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../../SkyTravelFx/src/icon-default-profile.png" />
</image>
</ImageView>
<Button fx:id="login" layoutX="153.0" layoutY="440.0" onAction="#handleButtonAction" style="-fx-background-color: #095a77;" text="Log In" textFill="WHITE">
<font>
<Font size="18.0" />
</font>
</Button>
<Label fx:id="label2" layoutX="152.0" layoutY="308.0" minHeight="16" minWidth="69" text="Password">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="label2" layoutX="150.0" layoutY="214.0" minHeight="16" minWidth="69" text="Username">
<font>
<Font size="18.0" />
</font>
</Label>
<TextField fx:id="username" layoutX="115.0" layoutY="241.0" />
<TextField fx:id="password" layoutX="115.0" layoutY="335.0" />
</children>
</AnchorPane>
<Button fx:id="admin" layoutX="621.0" layoutY="592.0" mnemonicParsing="false" style="-fx-background-color: #095a77;" text="Log In as Admin" textFill="WHITE">
<font>
<Font size="18.0" />
</font>
</Button>
<Button fx:id="user" layoutX="621.0" layoutY="675.0" mnemonicParsing="false" onAction="#btnClicked" prefHeight="39.0" prefWidth="153.0" style="-fx-background-color: #095a77;" text="Log In as User" textFill="WHITE">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</AnchorPane>
Here is the run-time error i am getting.
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:
javafx.fxml.LoadException: Error resolving
onAction='#handleButtonAction', either the event handler is not in the
Namespace or there is an error in the script.
file:/C:/Users/Dell/Documents/NetBeansProjects/SkyTravelsFx/dist/run1245920268/SkyTravelsFx.jar!/skytravelsfx/Login.fxml:47
at
javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103) at
javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
at
javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823) at
javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532) 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
skytravelsfx.SkyTravelsFx.start(SkyTravelsFx.java:23) 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 skytravelsfx.SkyTravelsFx
Java Result: 1 Deleting directory
C:\Users\Dell\Documents\NetBeansProjects\SkyTravelsFx\dist\run1245920268
jfxsa-run: BUILD SUCCESSFUL (total time: 4 seconds)
The stack trace tells you the problem:
Error resolving onAction='#handleButtonAction', either the event handler is not in the Namespace or there is an error in the script.
You have
<Button fx:id="login" layoutX="153.0" layoutY="440.0" onAction="#handleButtonAction" ... >
but your controller has no method called handleButtonAction. You probably want
<Button fx:id="login" layoutX="153.0" layoutY="440.0" onAction="#btnClicked" ... >