When my code hits the if statement it immediately throws the error
Exception in thread "Thread-4" java.lang.NullPointerException
at sample.Controller.getSiteLocation(Controller.java:125)
at sample.Controller.access$000(Controller.java:30)
at sample.Controller$1.run(Controller.java:72)
at java.lang.Thread.run(Thread.java:748)
The only thing i can think of is due to it being in a diff thread, because the checkbox is checked by default.
@FXML
CheckBox cboxOnSiteSearch;
@FXML
public void initialize() {
cboxOnSiteSearch.setSelected(true);
}
@FXML
private void QueryLocations(ActionEvent event)
{
Thread th = new Thread(new Runnable() {
@Override
public void run() {
Controller obj = new Controller();
Set<String> result = obj.getSiteLocation();
try {
Thread.sleep(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
th.setDaemon(true);
th.start();
}
private Set<String> getSiteLocation() {
if (cboxOnSiteSearch.isSelected())
{
//more code
}
//more code
}
What do I need to change so that this code does not produce an error?
Aucun commentaire:
Enregistrer un commentaire