Java fx error


Joined
Jan 14, 2022
Messages
4
Reaction score
0
everutime i try to launch my Java FX code( FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 600, 600); ) i get an error InvocationTargetException what do i do to fix it?
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
243
Reaction score
29
Hello and welcome! Can you please post your code, or at least your full stack trace? In code tags, please and thank you.
 
Joined
Jan 14, 2022
Messages
4
Reaction score
0
here
"C:\Program Files\Java\jdk-17.0.1\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.2\lib\idea_rt.jar=62836:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\omen\.m2\repository\org\openjfx\javafx-controls\17.0.0.1\javafx-controls-17.0.0.1.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-graphics\17.0.0.1\javafx-graphics-17.0.0.1.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-base\17.0.0.1\javafx-base-17.0.0.1.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-fxml\17.0.0.1\javafx-fxml-17.0.0.1.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-web\17.0.0.1\javafx-web-17.0.0.1.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-media\17.0.0.1\javafx-media-17.0.0.1.jar -p C:\Users\omen\.m2\repository\org\kordamp\ikonli\ikonli-core\12.2.0\ikonli-core-12.2.0.jar;C:\Users\omen\.m2\repository\org\controlsfx\controlsfx\11.1.0\controlsfx-11.1.0.jar;C:\Users\omen\.m2\repository\org\kordamp\bootstrapfx\bootstrapfx-core\0.4.0\bootstrapfx-core-0.4.0.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-web\17.0.0.1\javafx-web-17.0.0.1-win.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-graphics\17.0.0.1\javafx-graphics-17.0.0.1-win.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-media\17.0.0.1\javafx-media-17.0.0.1-win.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-base\17.0.0.1\javafx-base-17.0.0.1-win.jar;C:\Users\omen\.m2\repository\com\dlsc\formsfx\formsfx-core\11.3.2\formsfx-core-11.3.2.jar;C:\Users\omen\.m2\repository\org\openjfx\javafx-fxml\17.0.0.1\javafx-fxml-17.0.0.1-win.jar;C:\Users\omen\.m2\repository\org\kordamp\ikonli\ikonli-javafx\12.2.0\ikonli-javafx-12.2.0.jar;C:\Users\omen\.m2\repository\eu\hansolo\tilesfx\11.48\tilesfx-11.48.jar;C:\Users\omen\Documents\GitHub\breakArbuz\target\classes;C:\Users\omen\.m2\repository\org\openjfx\javafx-controls\17.0.0.1\javafx-controls-17.0.0.1-win.jar;C:\Users\omen\.m2\repository\net\synedra\validatorfx\0.1.13\validatorfx-0.1.13.jar -m school2045.edu.breakarbuz/school2045.edu.breakarbuz.HelloApplication
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:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
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:901)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: javafx.fxml.LoadException: Invalid identifier.
/C:/Users/omen/Documents/GitHub/breakArbuz/target/classes/school2045/edu/breakarbuz/helloView.fxml:12

at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2703)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:912)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:981)
at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:230)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:755)
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:2516)
at school2045.edu.breakarbuz/school2045.edu.breakarbuz.HelloApplication.start(HelloApplication.java:16)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
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:184)
... 1 more
Exception running application school2045.edu.breakarbuz.HelloApplication

Process finished with exit code 1
 
Joined
Jan 14, 2022
Messages
4
Reaction score
0
and also helloView file:
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="school2045.edu.breakarbuz.HelloController">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<GridPane>
<Button onAction="#Lunka1" fx:id="#Lunka1" visible="false" GridPane.columnIndex="0" GridPane.RowIndex="0"/>
<Button onAction="#Lunka2" fx:id="#Lunka2" visible="true" GridPane.columnIndex="1" GridPane.RowIndex="0"/>
<Button onAction="#Lunka3" fx:id="#Lunka3" visible="false" GridPane.columnIndex="2" GridPane.RowIndex="0"/>
<Button onAction="#Lunka4" fx:id="#Lunka4" visible="false" GridPane.columnIndex="3" GridPane.RowIndex="0"/>
<Button onAction="#Lunka5" fx:id="#Lunka5" visible="false" GridPane.columnIndex="0" GridPane.RowIndex="1"/>
<Button onAction="#Lunka6" fx:id="#Lunka6" visible="true" GridPane.columnIndex="1" GridPane.RowIndex="1"/>
<Button onAction="#Lunka7" fx:id="#Lunka7" visible="false" GridPane.columnIndex="2" GridPane.RowIndex="1"/>
<Button onAction="#Lunka8" fx:id="#Lunka8" visible="false" GridPane.columnIndex="3" GridPane.RowIndex="1"/>
<Button onAction="#Lunka9" fx:id="#Lunka9" visible="false" GridPane.columnIndex="0" GridPane.RowIndex="2"/>
<Button onAction="#Lunka10" fx:id="#Lunka10" visible="true" GridPane.columnIndex="1" GridPane.RowIndex="2"/>
<Button onAction="#Lunka11" fx:id="#Lunka11" visible="false" GridPane.columnIndex="2" GridPane.RowIndex="2"/>
<Button onAction="#Lunka12" fx:id="#Lunka12" visible="false" GridPane.columnIndex="3" GridPane.RowIndex="2"/>
<Button onAction="#Lunka13" fx:id="#Lunka13" visible="false" GridPane.columnIndex="0" GridPane.RowIndex="3"/>
<Button onAction="#Lunka14" fx:id="#Lunka14" visible="true" GridPane.columnIndex="1" GridPane.RowIndex="3"/>
<Button onAction="#Lunka15" fx:id="#Lunka15" visible="false" GridPane.columnIndex="2" GridPane.RowIndex="3"/>
<Button onAction="#Lunka16" fx:id="#Lunka16" visible="false" GridPane.columnIndex="3" GridPane.RowIndex="3"/>
</GridPane>
</VBox>


then HelloController file:


import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

public class HelloController {
int clickedLunka, neededLunka;
Button Lunka1;
Button Lunka2;
Button Lunka3;
Button Lunka4;
Button Lunka5;
Button Lunka6;
Button Lunka7;
Button Lunka8;
Button Lunka9;
Button Lunka10;
Button Lunka11;
Button Lunka12;
Button Lunka13;
Button Lunka14;
Button Lunka15;
Button Lunka16;

public void mainMethod() {
while (true) {
neededLunka = (int) (Math.random() * 16 + 1);
switch (neededLunka) {
case 1 -> Lunka1.setVisible(true);
case 2 -> Lunka2.setVisible(true);
case 3 -> Lunka3.setVisible(true);
case 4 -> Lunka4.setVisible(true);
case 5 -> Lunka5.setVisible(true);
case 6 -> Lunka6.setVisible(true);
case 7 -> Lunka7.setVisible(true);
case 8 -> Lunka8.setVisible(true);
case 9 -> Lunka9.setVisible(true);
case 10 -> Lunka10.setVisible(true);
case 11 -> Lunka11.setVisible(true);
case 12 -> Lunka12.setVisible(true);
case 13 -> Lunka13.setVisible(true);
case 14 -> Lunka14.setVisible(true);
case 15 -> Lunka15.setVisible(true);
case 16 -> Lunka16.setVisible(true);
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
switch (neededLunka) {
case 1 -> Lunka1.setVisible(false);
case 2 -> Lunka2.setVisible(false);
case 3 -> Lunka3.setVisible(false);
case 4 -> Lunka4.setVisible(false);
case 5 -> Lunka5.setVisible(false);
case 6 -> Lunka6.setVisible(false);
case 7 -> Lunka7.setVisible(false);
case 8 -> Lunka8.setVisible(false);
case 9 -> Lunka9.setVisible(false);
case 10 -> Lunka10.setVisible(false);
case 11 -> Lunka11.setVisible(false);
case 12 -> Lunka12.setVisible(false);
case 13 -> Lunka13.setVisible(false);
case 14 -> Lunka14.setVisible(false);
case 15 -> Lunka15.setVisible(false);
case 16 -> Lunka16.setVisible(false);
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

@FXML
protected void Lunka1() {System.out.println(1);}
@FXML
protected void Lunka2() {System.out.println(2);}
@FXML
protected void Lunka3() {System.out.println(3);}
@FXML
protected void Lunka4() {System.out.println(4);}
@FXML
protected void Lunka5() {System.out.println(5);}
@FXML
protected void Lunka6() {System.out.println(6);}
@FXML
protected void Lunka7() {System.out.println(7);}
@FXML
protected void Lunka8() {System.out.println(8);}
@FXML
protected void Lunka9() {System.out.println(9);}
@FXML
protected void Lunka10() {System.out.println(10);}
@FXML
protected void Lunka11() {System.out.println(11);}
@FXML
protected void Lunka12() {System.out.println(12);}
@FXML
protected void Lunka13() {System.out.println(13);}
@FXML
protected void Lunka14() {System.out.println(14);}
@FXML
protected void Lunka15() {System.out.println(15);}
@FXML
protected void Lunka16() {System.out.println(16);}
}



and HelloApplication




import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.ImageCursor;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("helloView.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 600, 600);
Image image = new Image("file:src/main/resources/hammer.png");
scene.setCursor(new ImageCursor(image));
stage.setTitle("ARBUZ BREAKER OMG");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch();
}
}
 
Joined
Jan 14, 2022
Messages
4
Reaction score
0
i solved this problem by making them public and deleting hashtags, but still thank you!
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
243
Reaction score
29
Sorry that I'm so late. Just for future users (and my own curiosity), by making what public? It looks like real error is the "Invalid identifier," I guess on line 12 of your helloView.fxml? Was the identifier it was looking for a private method or class?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top