Edit: It's not something as simple as a nullpointerexception being thrown. The thread is working severable times before throwing the nullpointerexception meaning that it suddenly decides to stop working and I can't figure out why
Hello I have the following thread
private class IsCreditAdded implements Runnable{
ActionEvent evt;
public IsCreditAdded(ActionEvent evt){
this.evt = evt;
}
@Override
public void run(){
while (AddMinutes.creditChosen != true){
}
creditAdded(evt, AddMinutes.getEvt());
}
}
It waits for a boolean to change from a GUI class with options to select a value, and then when the boolean changes it executes a method called creditAdded with values evt(passed in from constructor), and a static getMethod which contains the ActionEvent which was selected
public void creditAdded(ActionEvent evt, ActionEvent duration){
System.out.println(evt.getActionCommand() + " " + duration.getActionCommand());
switch (evt.getActionCommand()){
case ("voipCredit"):
switch (duration.getActionCommand()){
case ("cancel"):
System.out.println("CANCEL");
disableButtons(evt, duration);
break;
}
addMinutes.dispose();
AddMinutes.reset();
sessionStorage.printTransActions();
}
Here is where the thread is created:
private void creditButtonActionPerformed(java.awt.event.ActionEvent evt) {
switch (evt.getActionCommand()){
case ("voipCredit"):
addMinutes = new AddMinutes();
addMinutes.setService("VOIP");
addMinutes.setVisible(true);
addMinutes.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addMinutes.setPrices(nf.format(SessionPrices.getVOIP_10_MINS()), nf.format(SessionPrices.getVOIP_30_MINS()),
nf.format(SessionPrices.getVOIP_1_HOUR()), nf.format(SessionPrices.getVOIP_ALL_DAY()));
threadVar = new Thread(new IsCreditAdded(evt));
threadVar.start();
disableAllButtons();
break;
}
}
Now the problem Im having is whenever I select the button which gives the getActionCommand 'cancel' it works two times, sometimes three, but then if I try it again I get a nullpointerexception. The actual error message I get is:
Exception in thread "Thread-6" java.lang.NullPointerException at com.aidanmoore.InternetCafeGUI.creditAdded(InternetCafeGUI.java:416) at com.aidanmoore.InternetCafeGUI$IsCreditAdded.run(InternetCafeGUI.java:411) at java.lang.Thread.run(Thread.java:745) BUILD STOPPED (total time: 9 seconds)"
I can't figure out why it is throwing this exception after hours of searching for similar problems others have had and since the thread works x amount of times before throwing the exception I Cant work out why it suddenly breaks