JAVAFX CheckBox thread
up vote
0
down vote
favorite
I have a list of Japanese dishes and the user select which dish will commande. I'm trying to check which ones of the Checkboxes are selected from a thread and print the price in a Label but when I run my code it returns 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);
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MenuController">
<children>
<AnchorPane prefHeight="486.0" prefWidth="617.0">
<children>
<HBox layoutX="195.0" layoutY="10.0" prefHeight="49.0" prefWidth="193.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="MENU" textAlignment="CENTER" wrappingWidth="195.6796875">
<font>
<Font size="52.0" />
</font>*
</Text>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="160.0" prefHeight="26.0" prefWidth="578.0">
<children>
<CheckBox fx:id="soupeMiso" mnemonicParsing="false" text="Soupe Miso">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="salade1" mnemonicParsing="false" text="Salade">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="soupe_miso_EBI" mnemonicParsing="false" text="Supe Miso EBI">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="275.0" prefHeight="26.0" prefWidth="578.0" />
<Label fx:id="textPrice" layoutX="204.0" layoutY="393.0" prefHeight="44.0" prefWidth="196.0" text="price:">
<font>
<Font size="38.0" />
</font>
</Label>
<Button fx:id="order" layoutX="215.0" layoutY="358.0" mnemonicParsing="false" onAction="#selectedSushi" text="ORDER" />
</children>
</AnchorPane>
Error:
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)
java multithreading javafx checkbox nullpointerexception
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 1 more comment
up vote
0
down vote
favorite
I have a list of Japanese dishes and the user select which dish will commande. I'm trying to check which ones of the Checkboxes are selected from a thread and print the price in a Label but when I run my code it returns 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);
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MenuController">
<children>
<AnchorPane prefHeight="486.0" prefWidth="617.0">
<children>
<HBox layoutX="195.0" layoutY="10.0" prefHeight="49.0" prefWidth="193.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="MENU" textAlignment="CENTER" wrappingWidth="195.6796875">
<font>
<Font size="52.0" />
</font>*
</Text>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="160.0" prefHeight="26.0" prefWidth="578.0">
<children>
<CheckBox fx:id="soupeMiso" mnemonicParsing="false" text="Soupe Miso">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="salade1" mnemonicParsing="false" text="Salade">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="soupe_miso_EBI" mnemonicParsing="false" text="Supe Miso EBI">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="275.0" prefHeight="26.0" prefWidth="578.0" />
<Label fx:id="textPrice" layoutX="204.0" layoutY="393.0" prefHeight="44.0" prefWidth="196.0" text="price:">
<font>
<Font size="38.0" />
</font>
</Label>
<Button fx:id="order" layoutX="215.0" layoutY="358.0" mnemonicParsing="false" onAction="#selectedSushi" text="ORDER" />
</children>
</AnchorPane>
Error:
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)
java multithreading javafx checkbox nullpointerexception
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How is thethreadPriceinvoked? How is the object you call this for created, how do you load the fxml and how does the fxml look (The parts with theCheckBoxes and possibly theNodeusingthreadPriceas event handler seem to of interest here.) Furthermore what are you trying to achieve using aThreadhere? It's most likely that theCheckBoxes do not change between calling thethreadPricemethod and the execution of the runnable used withPlatform.runLater.
– fabian
2 days ago
You get theNullPointerExceptionat this lineString strPrice = Integer.toString(price);?
– Bo Halim
2 days ago
the issue is in salade.isSelected that returns null, i change the code and create a methode without thread like that: @FXML private void selectedSushi(ActionEvent event) { System.out.println("Check box"); 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(); } String prix= Integer.toString(price); textPrice.setText("Prix:"+prix);}
– Asmaa MOHAMEDI
2 days ago
and it doesnt work, isSelected always returs null
– Asmaa MOHAMEDI
2 days ago
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kleopatra
2 days ago
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a list of Japanese dishes and the user select which dish will commande. I'm trying to check which ones of the Checkboxes are selected from a thread and print the price in a Label but when I run my code it returns 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);
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MenuController">
<children>
<AnchorPane prefHeight="486.0" prefWidth="617.0">
<children>
<HBox layoutX="195.0" layoutY="10.0" prefHeight="49.0" prefWidth="193.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="MENU" textAlignment="CENTER" wrappingWidth="195.6796875">
<font>
<Font size="52.0" />
</font>*
</Text>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="160.0" prefHeight="26.0" prefWidth="578.0">
<children>
<CheckBox fx:id="soupeMiso" mnemonicParsing="false" text="Soupe Miso">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="salade1" mnemonicParsing="false" text="Salade">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="soupe_miso_EBI" mnemonicParsing="false" text="Supe Miso EBI">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="275.0" prefHeight="26.0" prefWidth="578.0" />
<Label fx:id="textPrice" layoutX="204.0" layoutY="393.0" prefHeight="44.0" prefWidth="196.0" text="price:">
<font>
<Font size="38.0" />
</font>
</Label>
<Button fx:id="order" layoutX="215.0" layoutY="358.0" mnemonicParsing="false" onAction="#selectedSushi" text="ORDER" />
</children>
</AnchorPane>
Error:
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)
java multithreading javafx checkbox nullpointerexception
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a list of Japanese dishes and the user select which dish will commande. I'm trying to check which ones of the Checkboxes are selected from a thread and print the price in a Label but when I run my code it returns 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);
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MenuController">
<children>
<AnchorPane prefHeight="486.0" prefWidth="617.0">
<children>
<HBox layoutX="195.0" layoutY="10.0" prefHeight="49.0" prefWidth="193.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="MENU" textAlignment="CENTER" wrappingWidth="195.6796875">
<font>
<Font size="52.0" />
</font>*
</Text>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="160.0" prefHeight="26.0" prefWidth="578.0">
<children>
<CheckBox fx:id="soupeMiso" mnemonicParsing="false" text="Soupe Miso">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="salade1" mnemonicParsing="false" text="Salade">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="soupe_miso_EBI" mnemonicParsing="false" text="Supe Miso EBI">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</CheckBox>
</children>
</HBox>
<HBox layoutX="25.0" layoutY="275.0" prefHeight="26.0" prefWidth="578.0" />
<Label fx:id="textPrice" layoutX="204.0" layoutY="393.0" prefHeight="44.0" prefWidth="196.0" text="price:">
<font>
<Font size="38.0" />
</font>
</Label>
<Button fx:id="order" layoutX="215.0" layoutY="358.0" mnemonicParsing="false" onAction="#selectedSushi" text="ORDER" />
</children>
</AnchorPane>
Error:
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)
java multithreading javafx checkbox nullpointerexception
java multithreading javafx checkbox nullpointerexception
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
Zephyr
3,1091928
3,1091928
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
Asmaa MOHAMEDI
12
12
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Asmaa MOHAMEDI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How is thethreadPriceinvoked? How is the object you call this for created, how do you load the fxml and how does the fxml look (The parts with theCheckBoxes and possibly theNodeusingthreadPriceas event handler seem to of interest here.) Furthermore what are you trying to achieve using aThreadhere? It's most likely that theCheckBoxes do not change between calling thethreadPricemethod and the execution of the runnable used withPlatform.runLater.
– fabian
2 days ago
You get theNullPointerExceptionat this lineString strPrice = Integer.toString(price);?
– Bo Halim
2 days ago
the issue is in salade.isSelected that returns null, i change the code and create a methode without thread like that: @FXML private void selectedSushi(ActionEvent event) { System.out.println("Check box"); 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(); } String prix= Integer.toString(price); textPrice.setText("Prix:"+prix);}
– Asmaa MOHAMEDI
2 days ago
and it doesnt work, isSelected always returs null
– Asmaa MOHAMEDI
2 days ago
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kleopatra
2 days ago
|
show 1 more comment
How is thethreadPriceinvoked? How is the object you call this for created, how do you load the fxml and how does the fxml look (The parts with theCheckBoxes and possibly theNodeusingthreadPriceas event handler seem to of interest here.) Furthermore what are you trying to achieve using aThreadhere? It's most likely that theCheckBoxes do not change between calling thethreadPricemethod and the execution of the runnable used withPlatform.runLater.
– fabian
2 days ago
You get theNullPointerExceptionat this lineString strPrice = Integer.toString(price);?
– Bo Halim
2 days ago
the issue is in salade.isSelected that returns null, i change the code and create a methode without thread like that: @FXML private void selectedSushi(ActionEvent event) { System.out.println("Check box"); 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(); } String prix= Integer.toString(price); textPrice.setText("Prix:"+prix);}
– Asmaa MOHAMEDI
2 days ago
and it doesnt work, isSelected always returs null
– Asmaa MOHAMEDI
2 days ago
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kleopatra
2 days ago
How is the
threadPrice invoked? How is the object you call this for created, how do you load the fxml and how does the fxml look (The parts with the CheckBoxes and possibly the Node using threadPrice as event handler seem to of interest here.) Furthermore what are you trying to achieve using a Thread here? It's most likely that the CheckBoxes do not change between calling the threadPrice method and the execution of the runnable used with Platform.runLater.– fabian
2 days ago
How is the
threadPrice invoked? How is the object you call this for created, how do you load the fxml and how does the fxml look (The parts with the CheckBoxes and possibly the Node using threadPrice as event handler seem to of interest here.) Furthermore what are you trying to achieve using a Thread here? It's most likely that the CheckBoxes do not change between calling the threadPrice method and the execution of the runnable used with Platform.runLater.– fabian
2 days ago
You get the
NullPointerException at this line String strPrice = Integer.toString(price); ?– Bo Halim
2 days ago
You get the
NullPointerException at this line String strPrice = Integer.toString(price); ?– Bo Halim
2 days ago
the issue is in salade.isSelected that returns null, i change the code and create a methode without thread like that: @FXML private void selectedSushi(ActionEvent event) { System.out.println("Check box"); 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(); } String prix= Integer.toString(price); textPrice.setText("Prix:"+prix);}
– Asmaa MOHAMEDI
2 days ago
the issue is in salade.isSelected that returns null, i change the code and create a methode without thread like that: @FXML private void selectedSushi(ActionEvent event) { System.out.println("Check box"); 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(); } String prix= Integer.toString(price); textPrice.setText("Prix:"+prix);}
– Asmaa MOHAMEDI
2 days ago
and it doesnt work, isSelected always returs null
– Asmaa MOHAMEDI
2 days ago
and it doesnt work, isSelected always returs null
– Asmaa MOHAMEDI
2 days ago
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kleopatra
2 days ago
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kleopatra
2 days ago
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Asmaa MOHAMEDI is a new contributor. Be nice, and check out our Code of Conduct.
Asmaa MOHAMEDI is a new contributor. Be nice, and check out our Code of Conduct.
Asmaa MOHAMEDI is a new contributor. Be nice, and check out our Code of Conduct.
Asmaa MOHAMEDI is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238277%2fjavafx-checkbox-thread%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
How is the
threadPriceinvoked? How is the object you call this for created, how do you load the fxml and how does the fxml look (The parts with theCheckBoxes and possibly theNodeusingthreadPriceas event handler seem to of interest here.) Furthermore what are you trying to achieve using aThreadhere? It's most likely that theCheckBoxes do not change between calling thethreadPricemethod and the execution of the runnable used withPlatform.runLater.– fabian
2 days ago
You get the
NullPointerExceptionat this lineString strPrice = Integer.toString(price);?– Bo Halim
2 days ago
the issue is in salade.isSelected that returns null, i change the code and create a methode without thread like that: @FXML private void selectedSushi(ActionEvent event) { System.out.println("Check box"); 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(); } String prix= Integer.toString(price); textPrice.setText("Prix:"+prix);}
– Asmaa MOHAMEDI
2 days ago
and it doesnt work, isSelected always returs null
– Asmaa MOHAMEDI
2 days ago
Please provide a Minimal, Complete, and Verifiable example that demonstrates the problem.
– kleopatra
2 days ago