The code below keeps giving a java.lang.NumberFormatException: empty String
:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt
The string you're trying to parse as double is empty. You need to check if the getText() method returns a non empty string before trying to do the parsing cause you can't parse to double an empty string.
You should check your field before parse double:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
double AText = ParseDouble(angleAField.getText());
double BText = ParseDouble(angleBField.getText());
double CText = ParseDouble(angleCField.getText());
double aText = ParseDouble(sideaField.getText());
double bText = ParseDouble(sidebField.getText());
double cText = ParseDouble(sidecField.getText());
// other code here same
}
double ParseDouble(String strNumber) {
if (strNumber != null && strNumber.length() > 0) {
try {
return Double.parseDouble(strNumber);
} catch(Exception e) {
return -1; // or some value to mark this field is wrong. or make a function validates field first ...
}
}
else return 0;
}