I'm trying to get two nulls to compare, keeps throwing java.lang.NullPointerException in Eclipse
public Double x(String x){
if (x.split(" ")[1].equals("+")) {
// Ignore this stuff, it works
this.x = Double.valueOf(x.split(" ")[0]);
return new Double(x(Double.valueOf(x.split(" ")[2])));
} else if (x.split(" ")[1].equals("x")) {
// Ignore this stuff, it works
this.x = Double.valueOf(x.split(" ")[0]);
return new Double(x(Double.parseDouble(x.split(" ")[2])));
} else {
// The problem
return new Double(null);
}
}
public boolean testParser() {
boolean parseOne;
boolean parseTwo;
boolean parseThree;
if (calc.x("12 + 5") == 17) {
System.out.println("[ OK ] Parser adds correctly.");
parseOne = true;
} else {
System.out.println("[FAIL] Basic parsing fails to add.");
parseOne = false;
}
if (calc.x("12 x 5") == 60) {
System.out.println("[ OK ] Parser multiplies correctly.");
parseTwo = true;
} else {
System.out.println("[FAIL] Basic parsing fails to multiply.");
parseTwo = false;
}
// Comparing null with null here not working
if (calc.x("12 [ 3") == null) {
System.out.println("[ OK ] Parser returns null for operators which are not supported.");
parseThree = true;
} else {
System.out.println("[FAIL] Parser does not return null for operators which are not supported.");
parseThree = false;
}
return (parseOne && parseTwo && parseThree);
}
(Where calc is just the name of an instance of an object which the Double x(String x) method is in) Can anyone suggest a way to resolve this?