Issue
I made a square root calculator on android platform. I added different language in my app and my issue starts from here.
In languages with different symbols, like Chinese, I can print symbols. But when I touch to calculate button, app shuts down. I think issue starts with native symbols calculate.
Part of code
Double result;
textview show_result
result = Math.sqrt(Double.parseDouble(process.getText().toString()));
show_result.setText(result.toString());
Logcat
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: FATAL EXCEPTION: main
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: Process: ahmetgoksu.com.squareroot, PID: 11031
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: java.lang.NumberFormatException: Invalid double: "١"
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at java.lang.StringToReal.invalidReal(StringToReal.java:63)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at java.lang.StringToReal.parseDouble(StringToReal.java:269)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at java.lang.Double.parseDouble(Double.java:295)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at ahmetgoksu.com.squareroot.SquareRootSecondPage$1.onClick(SquareRootSecondPage.java:66)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at android.view.View.performClick(View.java:4438)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18422)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5001)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
10-29 03:26:34.946 11031-11031/ahmetgoksu.com.squareroot E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-29 03:26:34.950 705-865/system_process D/: HostConnection::get() New Host Connection established 0xb840c870, did 865
Solution
Double.Parse does not work with native languages as the string is parsed to double by checking each character in string with '0','1','2' characters.
you will have to parse it yourself calculate and parse back to native and print
Answered By - null pointer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.