My floatpoint formulas fail to function if there is a null variable. IE if one of the input variables is null, then no result is displayed in the TextView that displays the result.
As far as I can tell there are 2 solutions to this.
One sets the null EditTexts to 0
if they are null:
if (charisma == null) {
charisma.setText(0);
} else if (charisma != null) {
charisma.setText(getcharisma);
}
The other ignores null variables in the equation:
try {
float FP = Float.parseFloat(pref.getString("fp", ""));
float CHR = Float.parseFloat(charismafpvalue.getText().toString());
float PER = Float.parseFloat(persuasionfpvalue.getText().toString());
float ELI = Float.parseFloat(elicitationfpvalue.getText().toString());
float AML = Float.parseFloat(animalhandlingfpvalue.getText().toString());
if (charismafpvalue == null) {
fpr.setText(Float.toString(FP - (PER + ELI + AML)));
} else if (charismafpvalue != null) {
fpr.setText(Float.toString(FP - (CHR + PER + ELI + AML)));
}
}
catch (NumberFormatException ignore) {}
The problem is that my code for both of these fails to function. The values aren't set to 0 if they are null and the formula failed to function despite the if() {} else if() {}
code.
Any suggestions as to which is the better way to handle this? And how to implement it?