unable to import Gson java dependency to my Maven JavaFXML Project

I have imported a code for a Maven JavaFXML Project and can't add a Gson jar file to my project. it is a required dependency and right clicking the Java Dependency folder doesn't have any options to offer. I have installed the Gson jar file for use and I just need to add it to the project. Ignore the Gson in the 'Dependencies' folder as it was a solution that didn't help.
No description
195 Replies
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @AbuAbed! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st3w ago
Can you show your pom.xml? Is gson there? Do you have a module-info.java file? If so, please show that as well.
AbuAbed
AbuAbedOP3w ago
AbuAbed
AbuAbedOP3w ago
no module-info
dan1st
dan1st3w ago
You added it as a runtime dependency so it won't be avaiable at compile-time You probably want to remove the <scope>runtime</scope> from gson see https://canary.discord.com/channels/648956210850299986/1055111097562181684
AbuAbed
AbuAbedOP3w ago
I previously added it as compile but that didn't work Do I still need to try what you propose? I changed it to compile but I get the same problem
dan1st
dan1st3w ago
Did you update/reload the Maven project? What exactly happens?
AbuAbed
AbuAbedOP3w ago
No description
AbuAbed
AbuAbedOP3w ago
No description
AbuAbed
AbuAbedOP3w ago
This is how it is when I have the dependency as runtime
dan1st
dan1st3w ago
What does your pom.xml look like now?
AbuAbed
AbuAbedOP3w ago
AbuAbed
AbuAbedOP3w ago
This is how it looks like I added gson-parent but it made no difference Would you like me to export the project for you to view it?
dan1st
dan1st3w ago
and it's still listed under runtime dependencies but not in the dependencies list? You could try running mvn verify
AbuAbed
AbuAbedOP3w ago
that's old now it's under dependencies currently
dan1st
dan1st3w ago
ok Do you still have that? Can you run mvn verify from NetBeans on the project? (idk how exactly NetBeans works) If yes, it is the exact same error or a different error?
AbuAbed
AbuAbedOP3w ago
It looks like this now
No description
AbuAbed
AbuAbedOP3w ago
the package com.coursework2.hybrid04 has nothing in it
dan1st
dan1st3w ago
Are you sure you don't have a module-info.java file in your project?
AbuAbed
AbuAbedOP3w ago
nvm it does have it
dan1st
dan1st3w ago
Add a requires com.google.gson; to it
AbuAbed
AbuAbedOP3w ago
module com.coursework2.hybrid04 {
requires javafx.controls;
requires javafx.fxml;

opens com.coursework2.hybrid04 to javafx.fxml;
exports com.coursework2.hybrid04;
}
module com.coursework2.hybrid04 {
requires javafx.controls;
requires javafx.fxml;

opens com.coursework2.hybrid04 to javafx.fxml;
exports com.coursework2.hybrid04;
}
but it's in a different package
dan1st
dan1st3w ago
so?
AbuAbed
AbuAbedOP3w ago
No description
dan1st
dan1st3w ago
yeah, it should be like that What's the error in the module-info.java? Is opens com.coursework2.hybrid04 to javafx.fxml; the line with the error?
AbuAbed
AbuAbedOP3w ago
No description
AbuAbed
AbuAbedOP3w ago
no the one below it
dan1st
dan1st3w ago
ok so first the gson one the com.google.gson is wrong and needs to be something else you could try requires gson; I don't know the module name of gson by heart actually what error have you been getting there?
AbuAbed
AbuAbedOP3w ago
ok I changed it to that
dan1st
dan1st3w ago
Did it fix the error in the module-info.java?
AbuAbed
AbuAbedOP3w ago
No description
AbuAbed
AbuAbedOP3w ago
No description
AbuAbed
AbuAbedOP3w ago
No description
AbuAbed
AbuAbedOP3w ago
it fixed the error I will run the app and see if I run into more errors
dan1st
dan1st3w ago
there's still an error left
AbuAbed
AbuAbedOP3w ago
it's the export line
dan1st
dan1st3w ago
Do you want your classes to be in hybrid or in com.coursework2.hybrid04? yeah ik the error
AbuAbed
AbuAbedOP3w ago
I will have them in com instead Do I just copy paste and refactor?
dan1st
dan1st3w ago
move, not copy paste but yes, using the refactoring thing from NetBeans
AbuAbed
AbuAbedOP3w ago
No description
dan1st
dan1st3w ago
btw you might want to use the latest version of gson which is 2.11.0 at some point. If you do, you'd need to change the requires gson; to requires com.google.gson; Does the project work now?
AbuAbed
AbuAbedOP3w ago
Running it from HyBrid04.java, it gives me this error:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project HyBrid04: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile failed: Cannot invoke "java.lang.Throwable.getCause()" because "cause" is null -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project HyBrid04: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile failed: Cannot invoke "java.lang.Throwable.getCause()" because "cause" is null -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
dan1st
dan1st3w ago
Can you show the full build log? i.e. the full output you are getting?
AbuAbed
AbuAbedOP3w ago
Scanning for projects...

----------------------< com.coursework2:HyBrid04 >----------------------
Building HyBrid04 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------

>>> javafx-maven-plugin:0.0.4:run (default-cli) > process-classes @ HyBrid04 >>>

--- maven-resources-plugin:2.6:resources (default-resources) @ HyBrid04 ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 2 resources

--- maven-compiler-plugin:3.8.0:compile (default-compile) @ HyBrid04 ---
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 0.588 s
Finished at: 2024-12-07T18:02:45Z
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project HyBrid04: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile failed: Cannot invoke "java.lang.Throwable.getCause()" because "cause" is null -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Scanning for projects...

----------------------< com.coursework2:HyBrid04 >----------------------
Building HyBrid04 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------

>>> javafx-maven-plugin:0.0.4:run (default-cli) > process-classes @ HyBrid04 >>>

--- maven-resources-plugin:2.6:resources (default-resources) @ HyBrid04 ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 2 resources

--- maven-compiler-plugin:3.8.0:compile (default-compile) @ HyBrid04 ---
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 0.588 s
Finished at: 2024-12-07T18:02:45Z
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project HyBrid04: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile failed: Cannot invoke "java.lang.Throwable.getCause()" because "cause" is null -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
dan1st
dan1st3w ago
ah I think I know why you probably need a newer version of the maven-compiler-plugin You have
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
You probably want to change the <version>3.8.0</version> to <version>3.13.0</version> And if you want to use Java 17, you probably want to change the <release>11</release> to <release>17</release>. If you are using Java 21, that would be <release>21</release> and similar for other Java versions
AbuAbed
AbuAbedOP3w ago
Java dependency says that I am using JDK 22 should I put 22 instead?
dan1st
dan1st3w ago
21 or 22, yes you can also pick a lower version than the one you are using <release>21</release> means "requires at least Java 21"
AbuAbed
AbuAbedOP3w ago
I will try running it again
AbuAbed
AbuAbedOP3w ago
This is the output I received
dan1st
dan1st3w ago
ah you should update gson as I mentioned earlier that one change the version of gson to 2.11.0 and change the requires gson; to requires com.google.gson; in your module-info.java
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
AbuAbed
AbuAbedOP2w ago
I will get on that tomorrow
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
AbuAbed
AbuAbedOP2w ago
Okay I am back on the code I switched the version of gson to 2.11.0 and changed what's needed in module-info.java But now I get this error
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
@dan1st Nevermind Apparently I had to build the project to remove the error But when I run the project now I get this error instead
dan1st
dan1st2w ago
Could not find or load main class com.coursework2.hybrid04.App in module com.coursework2.hybrid04
seems like your main class is wrong
AbuAbed
AbuAbedOP2w ago
package com.coursework2.hybrid04;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class HyBrid04 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("HyBrid.fxml"));

Scene scene = new Scene(root);
scene.getStylesheets().add(HyBrid04.class.getResource("Style.css").toExternalForm());

primaryStage.setScene(scene);
primaryStage.setTitle("HyBrid04");
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}
package com.coursework2.hybrid04;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class HyBrid04 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("HyBrid.fxml"));

Scene scene = new Scene(root);
scene.getStylesheets().add(HyBrid04.class.getResource("Style.css").toExternalForm());

primaryStage.setScene(scene);
primaryStage.setTitle("HyBrid04");
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}
This is the java file that includes the main class I also checked out HyBrid.fxml it seems that errors there exist too
dan1st
dan1st2w ago
Can you show your pom.xml? Your main class is HyBrid04 but it expects the name App
dan1st
dan1st2w ago
<mainClass>com.coursework2.hybrid04.App</mainClass>
AbuAbed
AbuAbedOP2w ago
do I remove the .App?
dan1st
dan1st2w ago
change it to <mainClass>com.coursework2.hybrid04.HyBrid04</mainClass>
AbuAbed
AbuAbedOP2w ago
I assume that these are errors related to HyBrid.fxml
dan1st
dan1st2w ago
What is line 12 of HyBrid04? I think it doesn't find the FXML file
AbuAbed
AbuAbedOP2w ago
Parent root = FXMLLoader.load(getClass().getResource("HyBrid.fxml"));
dan1st
dan1st2w ago
getResource("HyBrid.fxml") returns null because HyBrid.fxml doesn't exist in the same directory as the class or in the corresponding directory it would need to be in src/main/resources
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
This is how it is
dan1st
dan1st2w ago
Is there a resource folder? src/main/resources preferably? similar to "Source packages" but next to it
AbuAbed
AbuAbedOP2w ago
There isn't
dan1st
dan1st2w ago
Can you show he full project tree/files?
AbuAbed
AbuAbedOP2w ago
No description
dan1st
dan1st2w ago
expand "Project Files" What's there?
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
bottom
dan1st
dan1st2w ago
Can you create a new directory src/main/resources? You can also do it outside of NetBeans
AbuAbed
AbuAbedOP2w ago
Alright give me a second Okay I am back I noticed the directory follows under the 'Other sources' folder
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
primary.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>

<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.coursework2.hybrid04.PrimaryController">
<children>
<Label text="Primary View" />
<Button fx:id="primaryButton" text="Switch to Secondary View" onAction="#switchToSecondary"/>
</children>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>

<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.coursework2.hybrid04.PrimaryController">
<children>
<Label text="Primary View" />
<Button fx:id="primaryButton" text="Switch to Secondary View" onAction="#switchToSecondary"/>
</children>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
secondary.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>

<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.coursework2.hybrid04.SecondaryController">
<children>
<Label text="Secondary View" />
<Button fx:id="secondaryButton" text="Switch to Primary View" onAction="#switchToPrimary" />
</children>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>

<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.coursework2.hybrid04.SecondaryController">
<children>
<Label text="Secondary View" />
<Button fx:id="secondaryButton" text="Switch to Primary View" onAction="#switchToPrimary" />
</children>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
Both of which have the error after calling fx:controller
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
@dan1st When I imported the project to a Maven project, these files weren't there to begin with Are they necessary to keep?
dan1st
dan1st2w ago
How did you create that? Note that it should be com/courseworks2/hybrid04
AbuAbed
AbuAbedOP2w ago
I didn't create that I assume it was made when I created the project
dan1st
dan1st2w ago
if the FXML references a controller class, it should exist then it's probably fine
AbuAbed
AbuAbedOP2w ago
So do I leave the primary and secondary fxml files alone?
dan1st
dan1st2w ago
? I meant if it reference a controller, you need to have it
AbuAbed
AbuAbedOP2w ago
I only have one controller class which is HyBridController.java
dan1st
dan1st2w ago
well your secondary FXML references a controller Do you need controller logic for it?
AbuAbed
AbuAbedOP2w ago
I believe that I only need one controller again I wasn't aware about the existence of these fxml files they are not included in the initial project I think that deleting them would fix the problems
dan1st
dan1st2w ago
you'll notice if you need another controller
AbuAbed
AbuAbedOP2w ago
That may be but as far as I am concerned I have one controller I will Javadoc the files
dan1st
dan1st2w ago
So what error do you currently have?
AbuAbed
AbuAbedOP2w ago
The primary and secondary FXMLs as I have shown above and some errors with HyBrid.fxml
dan1st
dan1st2w ago
yeah but what happens when you run it?
AbuAbed
AbuAbedOP2w ago
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.chart.BarChart?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<AnchorPane id="" fx:id="AnchorPane1" prefHeight="-1.0" prefWidth="-1.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hybrid.HyBridController">
<children>
<VBox spacing="10.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<HBox fx:id="HBox1" spacing="10.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<BarChart fx:id="BarChart1" animated="false" title="Courses &amp; Students">
<xAxis>
<CategoryAxis label="Courses" side="BOTTOM" fx:id="xAxis" />
</xAxis>
<yAxis>
<NumberAxis fx:id="yAxis" label="Students" side="LEFT" />
</yAxis>
</BarChart>
<TableView fx:id="TableView1">
<columns>
<TableColumn fx:id="TableColumn1" maxWidth="-1.0" minWidth="75.0" prefWidth="-1.0" text="Year" />
<TableColumn fx:id="TableColumn2" maxWidth="-1.0" minWidth="75.0" prefWidth="-1.0" text="Course" />
<TableColumn fx:id="TableColumn3" maxWidth="-1.0" minWidth="75.0" prefWidth="-1.0" text="Quantity" />
</columns>
</TableView>
</children>
</VBox>
</children>
</AnchorPane>
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.chart.BarChart?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<AnchorPane id="" fx:id="AnchorPane1" prefHeight="-1.0" prefWidth="-1.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hybrid.HyBridController">
<children>
<VBox spacing="10.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<HBox fx:id="HBox1" spacing="10.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<BarChart fx:id="BarChart1" animated="false" title="Courses &amp; Students">
<xAxis>
<CategoryAxis label="Courses" side="BOTTOM" fx:id="xAxis" />
</xAxis>
<yAxis>
<NumberAxis fx:id="yAxis" label="Students" side="LEFT" />
</yAxis>
</BarChart>
<TableView fx:id="TableView1">
<columns>
<TableColumn fx:id="TableColumn1" maxWidth="-1.0" minWidth="75.0" prefWidth="-1.0" text="Year" />
<TableColumn fx:id="TableColumn2" maxWidth="-1.0" minWidth="75.0" prefWidth="-1.0" text="Course" />
<TableColumn fx:id="TableColumn3" maxWidth="-1.0" minWidth="75.0" prefWidth="-1.0" text="Quantity" />
</columns>
</TableView>
</children>
</VBox>
</children>
</AnchorPane>
Give me a second
AbuAbed
AbuAbedOP2w ago
This is what I get
AbuAbed
AbuAbedOP2w ago
Here's an extension
dan1st
dan1st2w ago
seems like the issue is the FXML file is still not found
AbuAbed
AbuAbedOP2w ago
HyBrid.fxml? Do I move it to the package under src?
dan1st
dan1st2w ago
You are trying to access HyBrid.fxml but you have a primary.fxml at least here I don't see a HyBrid.fxml
AbuAbed
AbuAbedOP2w ago
This is the tree again
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
I will move it
dan1st
dan1st2w ago
FXML and CSS files belong in src/main/resources Java files in src/main/java (i.e. "Source Packages")
AbuAbed
AbuAbedOP2w ago
That's good to know
AbuAbed
AbuAbedOP2w ago
How do I comment in .fxml files? I need to blank out the primary and secondary files
dan1st
dan1st2w ago
<!-- comment here -->
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
This is in HyBrid.fxml
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
This is the HyBrid.fxml code
dan1st
dan1st2w ago
it's com.coursework2.hybrid04.HyBridController Is there any reason you are using JavaFX 13 in your pom.xml?
AbuAbed
AbuAbedOP2w ago
No, should I change that to 22?
dan1st
dan1st2w ago
probably, yes Since you moved the files now, are you getting a different error when running the application?
AbuAbed
AbuAbedOP2w ago
Nope
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
The application runs fine now
dan1st
dan1st2w ago
ok
AbuAbed
AbuAbedOP2w ago
Don't mind the missing data Ok, hopefully I don't run into these types of issues anymore Am I able to keep this post open in case I run into more problems later?
dan1st
dan1st2w ago
yes
AbuAbed
AbuAbedOP2w ago
So the app opens just fine but this error is personally bugging me
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
this is in HyBrid.fxml I noticed it while changing variables and parameters Should this be of any concern? @dan1st
dan1st
dan1st2w ago
you could try maing sure you are specifying the correct JavaFX version in the FXML file
dan1st
dan1st2w ago
it seems like you are not the only one experiencing that and it still works: https://stackoverflow.com/a/76965337/10871900
Stack Overflow
JavaFX LineChart Error: "Instances of javafx.scene.chart.LineChart ...
I am in the process of moving my JavaFX project from Java 8 to Java 11, JavaFX 17 for the past week or so. I also moved from Scenebuilder 8.5 to Scenebuilder JavaFX Version: 20.0.1. All in all it has
dan1st
dan1st2w ago
maybe there's an issue with a JavaFX plugin in NetBeans idk
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
AbuAbed
AbuAbedOP2w ago
@dan1st Back with a new problem, so I made a new method called constructObservableList() in HyBridController.java, and I called it in the start method in HyBrid04.java, but it shows an error as the method is never created or called, and both .java files are in the same package, what should I do here?
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
I tried importing the HyBridControlle.java but that didn't seem to work
dan1st
dan1st2w ago
Are both in the same class?
AbuAbed
AbuAbedOP2w ago
They are not As I mentioned, constructObservableList() method is in the HybridController.java, and I am trying to call it in the start method in HyBrid04.java
dan1st
dan1st2w ago
then you need to call it using yourObjectOfTheHybridControllerClass.constructObservableList()
AbuAbed
AbuAbedOP2w ago
oh nvm it's the class prefix I changed the method from private to public and made it static for syntax fix
dan1st
dan1st2w ago
I hope you know what static actually means?
AbuAbed
AbuAbedOP2w ago
when I managed to call the method, it gave me an error that I can't call a non-static method
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
AbuAbed
AbuAbedOP2w ago
Would it be a problem if I changed it to a static method?
dan1st
dan1st2w ago
if you know what you are doing and it makes sense from an architectural perspective, no but that requires knowing what static actually does and what instance methods are
JavaBot
JavaBot2w ago
Check out this StackOverflow question for details on the static keyword.
AbuAbed
AbuAbedOP2w ago
It shouldn't be a problem then
AbuAbed
AbuAbedOP2w ago
May I get an interpretation of this error?
dan1st
dan1st2w ago
add opens com.coursework2.hybrid04 to javafx.fxml; to your module-info.java JavaFX is trying to access com.coursework2.hybrid04.Sales#Year (I guess because of that being referenced in FXML) but it is not allowed
AbuAbed
AbuAbedOP2w ago
I already have this in that file:
module com.coursework2.hybrid04 {
requires javafx.controls;
requires javafx.fxml;
requires com.google.gson;

opens com.coursework2.hybrid04 to javafx.fxml;
exports com.coursework2.hybrid04;
}
module com.coursework2.hybrid04 {
requires javafx.controls;
requires javafx.fxml;
requires com.google.gson;

opens com.coursework2.hybrid04 to javafx.fxml;
exports com.coursework2.hybrid04;
}
dan1st
dan1st2w ago
Ah It's about gson add opens com.coursework2.hybrid04 to com.google.gson;
AbuAbed
AbuAbedOP2w ago
No description
AbuAbed
AbuAbedOP2w ago
What's the correct syntax?
dan1st
dan1st2w ago
ah it might be opens com.coursework2.hybrid04 to com.google.gson, javafx.fxml; or something like that so both in one statement
AbuAbed
AbuAbedOP2w ago
Alright that fixed it but now running the code seems to crash the application as soon as it starts no errors in the output this time
dan1st
dan1st2w ago
debug it? btw you can also inspect the code generated by the annotation processor
AbuAbed
AbuAbedOP2w ago
where can I find the annotation processor?
dan1st
dan1st2w ago
what do you mean with finding it?
AbuAbed
AbuAbedOP2w ago
I tried debugging the code but I still can't find the issue, both the log and debugger console are devoid of errors
dan1st
dan1st2w ago
what exactly happens?
AbuAbed
AbuAbedOP2w ago
I will send a screen recording nevermind I will explain it in detail When I run the app after 7 seconds, it opens the JavaFX application window which should show graphs and a table, but in a split second the app window closes itself without displaying anything
dan1st
dan1st2w ago
Did you add a breakpoint in the handler of that button?
AbuAbed
AbuAbedOP2w ago
I added a breakpoint to the main method, which didn't show me anything that resembles an error. But when I add the breakpoint to the start method in HyBrid04.java, I get this error in the debugger console: Not able to submit breakpoint LineBreakpoint HyBrid04.java : 33, reason: No executable location available at line 33 in class com.coursework2.hybrid04.HyBrid04.
dan1st
dan1st2w ago
What is line 33? Also why in the start() method?
AbuAbed
AbuAbedOP2w ago
line 33 is the calling of the start() method and I thought it might indicate something
dan1st
dan1st2w ago
Why are you setting a breakpoint there? It starts correctly, right?
AbuAbed
AbuAbedOP2w ago
the application window does start, yes
dan1st
dan1st2w ago
then add the breakpoint in the handler of the button that causes the crash/window to close itself
AbuAbed
AbuAbedOP2w ago
I don't have any button that closes the window Here's HyBrid04.java which contains the main() method
dan1st
dan1st2w ago
(the message about annotation processors was me confusing this with another question)
AbuAbed
AbuAbedOP2w ago
Oh
dan1st
dan1st2w ago
Didn't you say something about the app window closing when doing something?
AbuAbed
AbuAbedOP2w ago
I don't need to do anything for it to close, it just closes by itself
dan1st
dan1st2w ago
I don't see any GUI/JavaFX stuff here Is this the issue?
AbuAbed
AbuAbedOP2w ago
yes
AbuAbed
AbuAbedOP2w ago
Here's the start() method
dan1st
dan1st2w ago
So what's the thing that takes 7 seconds? Does it instantly close after these 7 seconds?
AbuAbed
AbuAbedOP2w ago
Yes, and the 7 seconds is retrieving data from a web service
dan1st
dan1st2w ago
Where does that happen? What about adding a breakpoint right after that happens?
AbuAbed
AbuAbedOP2w ago
It happens in the main method, and I added a breakpoint to try and see when the application launches but with debugging the window never shows up
dan1st
dan1st2w ago
How does the JavaFX application interact with the main method?
AbuAbed
AbuAbedOP2w ago
In the main method, before opening the app window, the code retrieves data and builds the code, then once that's done there's a series of lines printed in the console and then the application window opens
AbuAbed
AbuAbedOP2w ago
This is what the console gives me
dan1st
dan1st2w ago
oh there is a launch(args)
AbuAbed
AbuAbedOP2w ago
Yes
dan1st
dan1st2w ago
Is the main method declared in HyBrid04?
AbuAbed
AbuAbedOP2w ago
Yes
dan1st
dan1st2w ago
Is start() executed? When you debug start(), does it execute the primaryStage.show();?
AbuAbed
AbuAbedOP2w ago
No, when I debug start(), the debugger console gives me this: Not able to submit breakpoint LineBreakpoint HyBrid04.java : 33, reason: No executable location available at line 33 in class com.coursework2.hybrid04.HyBrid04. Invalid LineBreakpoint HyBrid04.java : 33 And it skips the debugging of that method and continues running the application. Line 33 is where start() is
dan1st
dan1st2w ago
btw regarding the error you got with your Discord message being blocked - that one should be fixed now What exactly is line 33? Is it HyBridController.constructSales();
AbuAbed
AbuAbedOP2w ago
No, it's public void start(Stage primaryStage) throws Exception {
dan1st
dan1st2w ago
btw you have Platform.exit(); in your application. You are aware that this just closes the application, right? you might want to try adding the breakpoint in the actual first line of actual code in that method
AbuAbed
AbuAbedOP2w ago
Okay I removed Platform.exit(); and the app window won't close itself anymore fixed the issue
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server