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" ... >
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.;
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.
Hi I am getting this error when trying to run my fxml file created in oracle scene builder the fxml file is labelled with the proper names for each of the buttons as well as the controller class being properly labelled, my control code for the in question error looks like this
package prog24178;
import javafx.collections.FXCollections;
import java.util.ArrayList;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;
import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;
import javafx.scene.control.ListView;
public class DataBaseController implements Config{
#FXML TextField txt1, txt2, txt3, txt4;
#FXML Button b1, b2, b3, b4, b5;
#FXML ListView<String> list;
#FXML private ArrayList<String> stringItems = new ArrayList<String>();
#FXML private ArrayList<Item> items = new ArrayList<Item>();
#FXML
public void add(ActionEvent e) {
int id = Integer.parseInt(txt1.getText());
String item = txt2.getText();
int quantity = Integer.parseInt(txt3.getText());
double price = Double.parseDouble(txt4.getText());
items.add(new Item(id, item, quantity, price));
list.getItems().clear();
stringItems.clear();
for(Item item1 : items) stringItems.add(item1.toString());
ObservableList<String> items = FXCollections.observableArrayList(stringItems);
list.setItems(items);
}
#FXML
public void load(ActionEvent e) {
items.clear();
stringItems.clear();
list.getItems().clear();
File f = new File(FILE);
try {
if(!f.exists()) f.createNewFile();
Scanner lines = new Scanner(f);
if(!lines.hasNextLine()) {
Alert alert = new Alert(AlertType.INFORMATION, "data file is empty\nenter car and click the save button");
alert.showAndWait();
}
else {
while(lines.hasNextLine()) {
Scanner line = new Scanner(lines.nextLine());
line.useDelimiter(":\\s*");
items.add(new Item(line.nextInt(), line.next(), line.nextInt(), line.nextDouble()));
line.close();
}
}
lines.close();
for(Item item1 : items)
list.getItems().add(item1.toString());
//stringCars.add(car.toString());
//ObservableList<String> items = FXCollections.observableArrayList(stringCars);
//list.setItems(items);
} catch (Exception e1) {
e1.printStackTrace();
}
}
#FXML
public void save(ActionEvent e) {
File f = new File(FILE);
try {
if(!f.exists()) f.createNewFile();
PrintWriter pw = new PrintWriter(f);
for(Item c : items)
pw.printf("%s:%s:%s:%d:%b\n",
c.getID(), c.getItem(), c.getQuantity(), c.getPrice());
pw.close();
} catch (Exception e1) {
e1.printStackTrace();
}
Alert alert = new Alert(AlertType.INFORMATION, "data is saved in a file\nyou can close the \napplication now");
alert.showAndWait();
}
#FXML
public void modify(ActionEvent e) {
}
#FXML
public void remove(ActionEvent e) {
}
}
the RunApp class
package prog24178;
import java.net.URL;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class RunApp extends javafx.application.Application implements Config{
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage ps) throws Exception {
URL res = this.getClass().getResource("control.fxml");
Parent scene = FXMLLoader.load(res);
Scene ourscene = new Scene(scene);
ps.setScene(ourscene);
ps.setTitle("Items Database");
ps.show();
}
}
the implemented config interface
as well as the full error message
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$1(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: Error resolving onAction='add', either the event handler is not in the Namespace or there is an error in the script.
/C:/Users/Canada%20Computers/workspace/Assign6/bin/prog24178/control.fxml:44
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 prog24178.RunApp.start(RunApp.java:17)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(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$4(WinApplication.java:186)
... 1 more
Exception running application prog24178.RunApp
FXML code
<?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.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="384.0" prefWidth="664.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="prog24178.RunApp">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="130.0" minWidth="10.0" prefWidth="51.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="276.0" minWidth="10.0" prefWidth="34.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="253.0" minWidth="0.0" prefWidth="39.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="307.0" minWidth="10.0" prefWidth="203.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="66.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="75.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="51.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="446.0" minWidth="10.0" prefWidth="148.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints maxHeight="48.0" minHeight="10.0" prefHeight="48.0" />
<RowConstraints maxHeight="48.0" minHeight="0.0" prefHeight="40.0" />
<RowConstraints maxHeight="44.0" minHeight="8.0" prefHeight="32.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="274.0" minHeight="10.0" prefHeight="32.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="274.0" minHeight="10.0" prefHeight="201.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="123.0" minHeight="10.0" prefHeight="31.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER_RIGHT" text="ID:" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
<TextField fx:id="txt1" prefHeight="25.0" prefWidth="46.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Item:" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
<TextField fx:id="txt2" GridPane.columnIndex="3" GridPane.rowIndex="2" />
<Label prefHeight="17.0" prefWidth="57.0" text="Quanitity:" GridPane.columnIndex="4" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
<TextField fx:id="txt3" GridPane.columnIndex="5" GridPane.rowIndex="2" />
<Label text="Price:" GridPane.columnIndex="6" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
<TextField fx:id="txt4" GridPane.columnIndex="7" GridPane.rowIndex="2">
<GridPane.margin>
<Insets />
</GridPane.margin>
</TextField>
<HBox prefHeight="29.0" prefWidth="516.0" spacing="10.0" GridPane.columnIndex="3" GridPane.columnSpan="2147483647" GridPane.rowIndex="3">
<children>
<Button fx:id="b1" mnemonicParsing="false" onAction="add" text="Add Item" />
<Button fx:id="b2" mnemonicParsing="false" onAction="#modify" text="Modify Item" />
<Button fx:id="b3" mnemonicParsing="false" onAction="#remove" prefHeight="25.0" prefWidth="107.0" text="Remove Item" />
</children>
<GridPane.margin>
<Insets top="10.0" />
</GridPane.margin>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="5">
<children>
<ListView fx:id="list" prefHeight="201.0" prefWidth="627.0">
<padding>
<Insets left="20.0" right="10.0" />
</padding>
</ListView>
</children>
</HBox>
<Label text="Items:" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
<HBox prefHeight="100.0" prefWidth="200.0" spacing="10.0" GridPane.columnIndex="3" GridPane.columnSpan="2147483647" GridPane.rowIndex="6">
<children>
<Button fx:id="b4" mnemonicParsing="false" onAction="#load" text="Load Data From File" />
<Button fx:id="b5" mnemonicParsing="false" onAction="#save" text="Save Data To File" />
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="3" GridPane.columnSpan="2147483647" GridPane.rowIndex="1">
<children>
<Label alignment="CENTER" prefHeight="48.0" prefWidth="318.0" text="Database of Items">
<font>
<Font size="26.0" />
</font>
</Label>
</children>
</HBox>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
</GridPane>
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"
So i made pretty simple application with Fxml with only label and text field, and two buttons but i get this error..
Exception in Application start method
And here is code
<?xml version="1.0" encoding="UTF-8*?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<GridPane alignment="CENTER" hgap="5.0" vgap="5.0">
<children>
<Text text="Dodavanje Kupca" GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="2">
<font>
<Font size= "30.0"/>
</font>
</Text>
<Label text="Ime Kupca" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<Label text="Prezime Kupca" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<Label text="Adresa Kupca" GridPane.columnIndex="0" GridPane.rowIndex="4"/>
<Label text="Email Kupca" GridPane.columnIndex="0" GridPane.rowIndex="5"/>
<Label text="Telefon Kupca" GridPane.columnIndex="0" GridPane.rowIndex="6"/>
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<TextField GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<TextField GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<TextField GridPane.columnIndex="1" GridPane.rowIndex="5"/>
<TextField GridPane.columnIndex="1" GridPane.rowIndex="6"/>
<HBox alignment="TOP_RIGHT" GridPane.columnIndex="1" GridPane.rowIndex="7">
<children>
<Button mnemonicParsing="true" text="Save"/>
<Button mnemonicParsing="true" text="Clear"/>
</children>
</HBox>
</children>
<padding>
<Insets bottom="16.0" left="15.0" right="15.0" top="15.0"/>
</padding>
</GridPane>
And here is the main class:
package main;
import java.net.URL;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class test extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
URL fxmlUrl= getClass().getClassLoader().getResource("view.fxml");
GridPane root= FXMLLoader.<GridPane>load(fxmlUrl);
Scene scena = new Scene(root);
stage.setScene(scena);
stage.show();
}
}
Sorry.
Here is another edit for stack trace.
Stack trace is little too big so again ill type some non sense here
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: javafx.fxml.LoadException:
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2504)
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 main.test.start(test.java:20)
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: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[10,22]
Message: A pseudo attribute name is expected.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.setInputSource(XMLStreamReaderImpl.java:214)
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.<init>(XMLStreamReaderImpl.java:184)
at com.sun.xml.internal.stream.XMLInputFactoryImpl.getXMLStreamReaderImpl(XMLInputFactoryImpl.java:262)
at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLStreamReader(XMLInputFactoryImpl.java:134)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2478)
... 17 more
Exception running application main.test
C:\Users\Djordje Zlatic\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)