java - Class Cast Exception when casting double -
i tried running next code. compiles, throws classcastexception. glad if can help me figure out why.
double costprice = 0; object[] possibilities = null; costprice = (double) joptionpane.showinputdialog( alphapos, "cost price:", "enter values", joptionpane.plain_message, null, possibilities, "");
joptionpane.showinputdialog()
returns object
(credits @seleenvirtuose) cannot cast double
, utilize double.parsedouble()
parse string double.
costprice = double.parsedouble(joptionpane.showinputdialog( alphapos, "cost price:", "enter values", joptionpane.plain_message, null, possibilities, ""));
also, can of on 1 line
as declaring double
variable , setting straight away, might declare , assign new value in 1 line
double costprice = double.parsedouble(joptionpane.showinputdialog( alphapos, "cost price:", "enter values", joptionpane.plain_message, null, possibilities, ""));
also, possibilities
variable null, pass null
parameter (unless have changed variable somewhere else)
double costprice = double.parsedouble(joptionpane.showinputdialog( alphapos, "cost price:", "enter values", joptionpane.plain_message, null, nulll, ""));
java casting double joptionpane
No comments:
Post a Comment