i have a liste of japenees dishes and the user select wich dish will commande, i'm trying to check wich one of checkbox are Selected in thread and print the price in Label but when i'm run my code it return NullPointerException
here is my code:
int price=0;
@FXML private Label textPrice;
//Dishes
@FXML private CheckBox salade;
@FXML private CheckBox soupeMiso;
@FXML private CheckBox soupe_miso_EBI;
public void threadPrice() {
new Thread(new Runnable() {
@Override public void run() {
Platform.runLater(new Runnable() {
@Override public void run() {
//selectedSushi() ;
if(salade.isSelected()) {
System.out.println("salade selected");
price=price+Sushi.SALADE.getPrice();
}
if(soupeMiso.isSelected()) {
price=price+Sushi.SOUPE_MISOU.getPrice();
}
if(soupe_miso_EBI.isSelected()) {
price=price+Sushi.SOUPE_MISOU_EBI.getPrice();
}
}
});
}}).start();
String strPrice = Integer.toString(price);
textPrice.setText("price:"+strPrice);
}
Error:
enter code here
Exception in thread "JavaFX Application Thread"
java.lang.NullPointerException
at application.MenuController$1$1.run(MenuController.java:143)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
Aucun commentaire:
Enregistrer un commentaire