#Does anyone here use JavaFX? I have a little trouble figuring out how to make the second form work

49 messages · Page 1 of 1 (latest)

sick roost
#

Even after I use the FXMLLoader to get the first form through its designated controller, it keeps telling Exception whenever I press the button prompted to transfer me to the next form

untold stirrupBOT
#

This post has been reserved for your question.

Hey @sick roost! 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 closed 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.

sonic stirrup
sick roost
#

It's like, 1 main app, 2 controllers for their 2 fxml files

pallid steeple
sonic stirrup
#

^

hushed hareBOT
#

Okay so
I tried doing a separate calculator to do a program that would do both gross and net

public class CalcuServiceImpl {

static CalcuServiceImpl calcService = null;

public static CalcuServiceImpl getCalcuService(){
    if(calcService == null)
        calcService = new CalcuServiceImpl();
    return calcService;
}

Calcu calcu;
public CalcuServiceImpl(){
    calcu = new Calcu();
}

public Calcu get(){
    return calcu;
}

}

  1. public class Calcu {
    int num1 = 0;
    int num2= 0;
    int sum= 0;
    } ```

This message has been formatted automatically. You can disable this using /preferences.

sick roost
#

For what I tried, it seemed to have no errors

#

Second form goes kapoot everytime I press the prompt where it's supposed to output it

sonic stirrup
#

Could you send the error code

sick roost
#

Which one, cuz it doesn't read any errors for me
You mean the error it outputted?

sonic stirrup
#

Yeah mb just woke up

#

Are you attempting to create a new window or just call this class?

sick roost
#

it's either i didn't put some of the Calcu codes on my first controller or I forgot to put a get and set for it

sonic stirrup
#

Would you mind sending the .java and fxml files to me so I can quickly run it on my end.

If not, could you show the code which your creating the new window.

sonic stirrup
# sick roost Hold on

Think I found the issue, here's how I did it so you know how to debug this type of issue.

Firstly I ran and tested the program until I hit the error point, from then, I looked to the bottom of the terminal and looked for the highlighted blue section, this tells us the error is line 30 in first controller.

Above that we can see the actual error is that the field **hoursWorkedField **was null. To fix this I just had to go rename this variable to the one that is found in your FXML which is hoursField, after that it ran without the error and displayed the second window.

Let me know if this fixes the problem.

sick roost
#

Wait, hoursField? How come?

#

It's just a public Text field

sonic stirrup
# sick roost Wait, hoursField? How come?

If you have a look at your PrimaryController FXML file, you will see a highlighted field at the bottom on line 38.

That is because the FX:ID="hoursField" hasn't got a reference in controller, so you were referencing a ID that did not exist in your FXML.

sick roost
#

It couldn't have been the only error

sonic stirrup
#

Everything worked fine for me afterwards

#

try it on your end and see if it works

#

You can make it private, but would then need to add the @FXML annotation to make it visible to JavaFX.

But to explain a bit more clearly:

Your variable named hoursWorkedField would work perfectly fine, it's name was simply not correctly referencing the FX:ID name you set in your FXML file. As such, when the program attempted to get a value from that textfield it could not, since no textfield was created with that name, so we got a NullPointerException error each time.

But, if we change the hoursWorkedField to match the name you put in your FXML file which is hoursField you will then be able to use the field values in the code.

sick roost
#

I'll go ahead and try for myself

#

Thank you

untold stirrupBOT
# sick roost Thank you

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

sick roost
#

Shouldn't have said it too soon

sonic stirrup
#

Did you run into an issue?

sick roost
sonic stirrup
#

Ah, mb, misunderstood what you said.

sick roost
#

The problem might be the same as for the calculating one

#

Okay, scratch that, I figured out the Back Button

#

The calculating one needs to be reconfigured because it just outputs zeroes

sonic stirrup
#

The back button is a similar issue. You are referencing a button back but you are not referencing the one inside the FXML file, you will need to add a FX:ID to the button and it should fix that problem.

sick roost
sonic stirrup
sick roost
#

It's not my intent to remove it completely, but I think this works better

untold stirrupBOT
#

💤 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.

sick roost
#

@sonic stirrup Uh hello? you still there?