I am trying to have the user input a number, and then that number is used to populate
a text field on a jform. However it keeps giving me errors. If I have the textfield call the str it gives me a numberformatexception, if I have it call the int variable it says it has to be a string…
public static String prePaidstr = "";
public static double prePaidint = 0;
prePaidstr =
JOptionPane.showInputDialog("Enter any amount prepaid:");
prePaidint = Double.parseDouble(prePaidstr);
jTextField13.setText(InvoiceSelectionUI.prePaidstr)
parseDoubleconverts aStringinto aDouble, which is why it complains if you try to pass it adouble.A NumberFormatException is thrown when
parseDoubleis unable to successfully turn a String into a double; in this case it’s because you’re trying toparseDoubleon an empty string.prePaidStrneeds to contain something like"1.99"– e.g. something that, to a human, looks like aDouble.