Does anyone know how to use Expression in Android Studio?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Does anyone know how to use Expression in Android Studio?



I'm making a calculator in Android Studio and am facing a problem.



Here is my code:


String input = getinput();
try
if (!isEmpty() && !stateError)
if (input.contains("x"))
input.replaceAll("x","*");

Expression expression = new ExpressionBuilder(input).build();

catch (Exception e)



When I type Expression, it shows the error:


Expression



"Cannot resolve symbol 'Expression'."



Is there any solution to solve this problem?





Just from looking around online, I don't think Expression or ExpressionBuilder is part of the Android library. If so, then you'll get a "Cannot resolve symbol Expression" error if you haven't found some library that supports it.
– LAD
Aug 8 at 3:25



Expression


ExpressionBuilder





what you want to do with this code ?
– Sagar Nayak
Aug 8 at 3:27





Use this library: http://javaluator.sourceforge.net/en/home/
– Rabee
Aug 8 at 3:30





Thanks everyone. I need to use this to calculate my answer.
– T3rrance Low
Aug 8 at 3:46





1 Answer
1



I don't know if you have found this or not, but there is this site that I found that seems to be the API for Expression and ExpressionBuilder called exp4j.


Expression


ExpressionBuilder



If that is in fact the API, then this is the download link for it.



Another way to evaluate an equation from a String in Java is to use the ScriptEngine interface along with the ScriptEngineManager class. You can use it like the following:


String


ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("javascript");

try
String result = engine.eval(stringEquation).toString();
System.out.println("Result: "+result);

catch (ScriptException se)
// Handle error






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard