简体   繁体   English

有人知道如何在Android Studio中使用Expression吗?

[英]Does anyone know how to use Expression in Android Studio?

I'm making a calculator in Android Studio and am facing a problem. 我正在Android Studio中制作计算器,但遇到了问题。

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? 有解决此问题的解决方案吗?

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. 我不知道您是否找到了这个,但是我发现这个站点似乎是ExpressionExpressionBuilder的API,称为exp4j。

If that is in fact the API, then this is the download link for it. 如果实际上是API,则这是的下载链接


Another way to evaluate an equation from a String in Java is to use the ScriptEngine interface along with the ScriptEngineManager class. 从Java中的String求值方程式的另一种方法是将ScriptEngine接口与ScriptEngineManager类一起使用。 You can use it like the following: 您可以像以下方式使用它:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有谁知道如何更改 Visual Studio 代码主题? - Does anyone know how to change Visual Studio Code Theme? 有谁知道在J2ME上如何成功使用预处理? - Does anyone know how succesfully use preprocessing on J2ME? 任何人都知道如何在Android Studio中修复“无法解决符号'注入'”错误? - Anyone know how to fix “Can't resolve symbol 'Inject'” error in Android Studio? 有谁知道如何在R中连接localhost? - Does anyone know how to connect localhost in R? 有人知道如何显示BitmapField吗? - Does anyone know how to display a BitmapField? 有谁知道如何在不使用Java密钥库的情况下使用StartCom SSL或使用自定义密钥库? - Does anyone know how to use StartCom SSL without keystore in Java OR use a custom keystore? 有谁知道如何从Android 2.1设备获取本地日期和时间? - Does anyone know how to get the local date and time from Android 2.1 device? 有谁知道如何在“元注释”中使用Spring的ImportResource注释? - Does anyone have know how to use Spring's ImportResource annotation in a “meta-annotation”? 我不能将Android Studio与JDK 1.8一起使用。 还有其他人有这个问题吗? - I cannot use Android Studio with JDK 1.8. Does anyone else have this issue? 有谁知道这个“LookAndFeel”的名字吗? - Does anyone know the name of this “LookAndFeel”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM