I am building a simple calculator in android, i already made it work with simple x operator x form but i am trying to make it work with more than 2 tokens, and while using parenthesis.
I am using an add-on Library to do the interpretation. EDIT: doccumentation for Interpreter Class: http://www.beanshell.org/javadoc/bsh/Interpreter.html
I tried using this code in java standalone and it worked:
public double evaluate(String express) {
double value = 0;
String answer = null;
String base = "result = ";
Interpreter interpreter = new Interpreter();
try {
interpreter.eval(base + express);
answer = interpreter.get("result").toString();//this line
value = Double.parseDouble(answer);
} catch (EvalError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But when i used it in android, the toString() method is throwing a nullpointerexception, why is that? why in android specifically?