0

I am trying to develop an app which crashes when I include any sort of math parser. App works fine otherwise when I comment out the math parser. I tried other parsers, still the same problem. Any ideas why this is happening? Below are some screen shots.

  1. Manifest enter image description here

  2. MainActivity File enter image description here

  3. Project Explorer

enter image description here

LogCat

04-24 01:13:15.440: D/AndroidRuntime(3481): Shutting down VM
04-24 01:13:15.440: W/dalvikvm(3481): threadid=1: thread exiting with uncaught exception (group=0xb1a74ba8)
04-24 01:13:15.460: E/AndroidRuntime(3481): FATAL EXCEPTION: main
04-24 01:13:15.460: E/AndroidRuntime(3481): Process: com.example.calculator, PID: 3481
04-24 01:13:15.460: E/AndroidRuntime(3481): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator/com.example.calculator.MainActivity}: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1:
04-24 01:13:15.460: E/AndroidRuntime(3481): }
04-24 01:13:15.460: E/AndroidRuntime(3481):  ^
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.os.Looper.loop(Looper.java:136)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at java.lang.reflect.Method.invokeNative(Native Method)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at java.lang.reflect.Method.invoke(Method.java:515)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at dalvik.system.NativeStart.main(Native Method)
04-24 01:13:15.460: E/AndroidRuntime(3481): Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1:
04-24 01:13:15.460: E/AndroidRuntime(3481): }
04-24 01:13:15.460: E/AndroidRuntime(3481):  ^
04-24 01:13:15.460: E/AndroidRuntime(3481):     at java.util.regex.Pattern.compileImpl(Native Method)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at java.util.regex.Pattern.compile(Pattern.java:411)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at java.util.regex.Pattern.<init>(Pattern.java:394)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at java.util.regex.Pattern.compile(Pattern.java:381)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at java.lang.String.replaceAll(String.java:1785)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.constants.utils.MathParserUtils.transformGropCharsIntoParentheses(MathParserUtils.java:41)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.validators.ExpressionValidator.evalIfExpressionIsWellFormed(ExpressionValidator.java:44)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.validators.ExpressionValidator.validate(ExpressionValidator.java:38)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.parser.LexicalTokenizer.validateExpression(LexicalTokenizer.java:116)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.parser.LexicalTokenizer.assignNewExpression(LexicalTokenizer.java:59)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.parser.LexicalTokenizer.setExpression(LexicalTokenizer.java:47)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.parser.Parser.splitExpressionInTokens(Parser.java:206)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.parser.Parser.shuntingYardAlgorithm(Parser.java:69)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.parser.Parser.setExpression(Parser.java:50)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.google.code.mathparser.impl.MathParserImpl.calculate(MathParserImpl.java:33)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at com.example.calculator.MainActivity.onCreate(MainActivity.java:42)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.Activity.performCreate(Activity.java:5231)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-24 01:13:15.460: E/AndroidRuntime(3481):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-24 01:13:15.460: E/AndroidRuntime(3481):     ... 11 more
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
John Smith
  • 418
  • 7
  • 21

3 Answers3

0

It might help you to post the Activity.java instead of the screenshot.

Your app is crashing because Result and MathParser are being declared outside the scope of where it can be initialized. (''where it can live''). Right now you'd be getting a Null Pointer Exception and so the resultant crash.

Please check More Info on the same.

For now, you can just shift your lines of MathParser and Result inside onCreate() and that should work.

Community
  • 1
  • 1
Pararth
  • 8,114
  • 4
  • 34
  • 51
  • It doesn't help :(. I have added the logcat. Sorry can't post the mainactivity. Its very long. It will take 2-3 pages. – John Smith Apr 24 '14 at 05:19
  • Hey...now your problem is the Reg Pattern: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1: 04-2 , let you know – Pararth Apr 24 '14 at 06:23
  • remove the image and pls post your new activity code...only till the onCreate() ends – Pararth Apr 24 '14 at 06:25
0

After trying tonnes of parser, Expr seems to work for me. No crashes. Also refer to this.

Community
  • 1
  • 1
John Smith
  • 418
  • 7
  • 21
0

Use mxparser (http://mathparser.org/)

It generally works well for Java apps.

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31296109) – Abhishek Dutt Mar 18 '22 at 03:11