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.
195 Replies
⌛
This post has been reserved for your question.
Hey @AbuAbed! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
Can you show your pom.xml? Is gson there?
Do you have a module-info.java file? If so, please show that as well.
no module-info
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/1055111097562181684I 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
Did you update/reload the Maven project?
What exactly happens?
This is how it is when I have the dependency as runtime
What does your pom.xml look like now?
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?
and it's still listed under runtime dependencies but not in the dependencies list?
You could try running
mvn verify
that's old now
it's under dependencies currently
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?It looks like this now
the package com.coursework2.hybrid04 has nothing in it
Are you sure you don't have a module-info.java file in your project?
nvm it does have it
Add a
requires com.google.gson;
to it
but it's in a different package
so?
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?no the one below it
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?ok I changed it to that
Did it fix the error in the module-info.java?
it fixed the error
I will run the app and see if I run into more errors
there's still an error left
it's the export line
Do you want your classes to be in
hybrid
or in com.coursework2.hybrid04
?
yeah ik the errorI will have them in com instead
Do I just copy paste and refactor?
move, not copy paste
but yes, using the refactoring thing from NetBeans
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?Running it from HyBrid04.java, it gives me this error:
Can you show the full build log?
i.e. the full output you are getting?
ah I think I know why
you probably need a newer version of the maven-compiler-plugin
You have
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 versionsJava dependency says that I am using JDK 22
should I put 22 instead?
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"I will try running it again
This is the output I received
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💤
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.
I will get on that tomorrow
💤
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.
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
@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
Could not find or load main class com.coursework2.hybrid04.App in module com.coursework2.hybrid04seems like your main class is wrong
This is the java file that includes the main class
I also checked out HyBrid.fxml
it seems that errors there exist too
Can you show your pom.xml?
Your main class is
HyBrid04
but it expects the name App
<mainClass>com.coursework2.hybrid04.App</mainClass>
do I remove the .App?
change it to
<mainClass>com.coursework2.hybrid04.HyBrid04</mainClass>
I assume that these are errors related to HyBrid.fxml
What is line 12 of HyBrid04?
I think it doesn't find the FXML file
Parent root = FXMLLoader.load(getClass().getResource("HyBrid.fxml"));
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/resourcesThis is how it is
Is there a resource folder?
src/main/resources preferably?
similar to "Source packages" but next to it
There isn't
Can you show he full project tree/files?
expand "Project Files"
What's there?
bottom
Can you create a new directory src/main/resources?
You can also do it outside of NetBeans
Alright give me a second
Okay I am back
I noticed the directory follows under the 'Other sources' folder
primary.fxml
secondary.fxml
Both of which have the error after calling fx:controller
@dan1st When I imported the project to a Maven project, these files weren't there to begin with
Are they necessary to keep?
How did you create that?
Note that it should be
com/courseworks2/hybrid04
I didn't create that
I assume it was made when I created the project
if the FXML references a controller class, it should exist
then it's probably fine
So do I leave the primary and secondary fxml files alone?
?
I meant if it reference a controller, you need to have it
I only have one controller class which is HyBridController.java
well your secondary FXML references a controller
Do you need controller logic for it?
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
you'll notice if you need another controller
That may be
but as far as I am concerned I have one controller
I will Javadoc the files
So what error do you currently have?
The primary and secondary FXMLs as I have shown above
and
some errors with HyBrid.fxml
yeah but what happens when you run it?
Give me a second
This is what I get
Here's an extension
seems like the issue is the FXML file is still not found
HyBrid.fxml?
Do I move it to the package under src?
You are trying to access HyBrid.fxml
but you have a primary.fxml
at least here
I don't see a HyBrid.fxml
This is the tree again
I will move it
FXML and CSS files belong in src/main/resources
Java files in src/main/java (i.e. "Source Packages")
That's good to know
How do I comment in .fxml files?
I need to blank out the primary and secondary files
<!-- comment here -->
This is in HyBrid.fxml
This is the HyBrid.fxml code
it's
com.coursework2.hybrid04.HyBridController
Is there any reason you are using JavaFX 13 in your pom.xml?No, should I change that to 22?
probably, yes
Since you moved the files now, are you getting a different error when running the application?
Nope
The application runs fine now
ok
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?
yes
So the app opens just fine but this error is personally bugging me
this is in HyBrid.fxml
I noticed it while changing variables and parameters
Should this be of any concern?
@dan1st
you could try maing sure you are specifying the correct JavaFX version in the FXML file
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
maybe there's an issue with a JavaFX plugin in NetBeans idk
💤
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.
@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?I tried importing the HyBridControlle.java but that didn't seem to work
Are both in the same class?
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.javathen you need to call it using
yourObjectOfTheHybridControllerClass.constructObservableList()
oh nvm it's the class prefix
I changed the method from private to public and made it static for syntax fix
I hope you know what
static
actually means?when I managed to call the method, it gave me an error that I can't call a non-static method
💤
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.
Would it be a problem if I changed it to a static method?
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 areIt shouldn't be a problem then
May I get an interpretation of this error?
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 allowedI already have this in that file:
Ah
It's about gson
add
opens com.coursework2.hybrid04 to com.google.gson;
What's the correct syntax?
ah
it might be
opens com.coursework2.hybrid04 to com.google.gson, javafx.fxml;
or something like that
so both in one statementAlright 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
debug it?
btw you can also inspect the code generated by the annotation processor
where can I find the annotation processor?
what do you mean with finding it?
I tried debugging the code but I still can't find the issue, both the log and debugger console are devoid of errors
what exactly happens?
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
Did you add a breakpoint in the handler of that button?
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.
What is line 33?
Also why in the
start()
method?line 33 is the calling of the
start()
method
and I thought it might indicate somethingWhy are you setting a breakpoint there?
It starts correctly, right?
the application window does start, yes
then add the breakpoint in the handler of the button that causes the crash/window to close itself
I don't have any button that closes the window
Here's HyBrid04.java which contains the
main()
method(the message about annotation processors was me confusing this with another question)
Oh
Didn't you say something about the app window closing when doing something?
I don't need to do anything for it to close, it just closes by itself
I don't see any GUI/JavaFX stuff here
Is this the issue?
yes
Here's the
start()
methodSo what's the thing that takes 7 seconds?
Does it instantly close after these 7 seconds?
Yes, and the 7 seconds is retrieving data from a web service
Where does that happen?
What about adding a breakpoint right after that happens?
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
How does the JavaFX application interact with the main method?
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
This is what the console gives me
oh there is a
launch(args)
Yes
Is the
main
method declared in HyBrid04
?Yes
Is
start()
executed?
When you debug start()
, does it execute the primaryStage.show();
?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()
isbtw 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();
No, it's
public void start(Stage primaryStage) throws Exception {
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 methodOkay I removed
Platform.exit();
and the app window won't close itself anymore
fixed the issue💤
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.