0

I developed a simple calculator..everything is working fine ...calculator will add mul sub and div two numbers the problem is with the division section..t will work fine if the first number is larger than second number other wise the app will stopped unexpectedly msg will come...I am just giving my div code now...

divBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    firstNum = new BigDecimal(firstVal.getText().toString());
    secNum = new BigDecimal(secondVal.getText().toString());
    {
        result.setText(secNum.divide(firstNum).toString());
    }
    result.setText(firstNum.divide(secNum).toString());
    }
});

this is my logcat

04-01 13:08:19.647: V/TLINE(377): new: android.text.TextLine@408d45a0
04-01 13:08:19.787: V/TLINE(377): new: android.text.TextLine@408da4a0
04-01 13:08:28.146: D/AndroidRuntime(377): Shutting down VM
04-01 13:08:28.146: W/dalvikvm(377): threadid=1: thread exiting with uncaught exception (group=0x40014760)
04-01 13:08:28.156: E/AndroidRuntime(377): FATAL EXCEPTION: main
04-01 13:08:28.156: E/AndroidRuntime(377): java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result
04-01 13:08:28.156: E/AndroidRuntime(377):  at java.math.BigDecimal.divide(BigDecimal.java:1280)
04-01 13:08:28.156: E/AndroidRuntime(377):  at com.example.simplecalculator2.MainActivity$4.onClick(MainActivity.java:109)
04-01 13:08:28.156: E/AndroidRuntime(377):  at android.view.View.performClick(View.java:3110)
04-01 13:08:28.156: E/AndroidRuntime(377):  at android.view.View$PerformClick.run(View.java:11928)
04-01 13:08:28.156: E/AndroidRuntime(377):  at android.os.Handler.handleCallback(Handler.java:587)
04-01 13:08:28.156: E/AndroidRuntime(377):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-01 13:08:28.156: E/AndroidRuntime(377):  at android.os.Looper.loop(Looper.java:132)
04-01 13:08:28.156: E/AndroidRuntime(377):  at android.app.ActivityThread.main(ActivityThread.java:4025)
04-01 13:08:28.156: E/AndroidRuntime(377):  at java.lang.reflect.Method.invokeNative(Native Method)
04-01 13:08:28.156: E/AndroidRuntime(377):  at java.lang.reflect.Method.invoke(Method.java:491)
04-01 13:08:28.156: E/AndroidRuntime(377):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-01 13:08:28.156: E/AndroidRuntime(377):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-01 13:08:28.156: E/AndroidRuntime(377):  at dalvik.system.NativeStart.main(Native Method)
Ahmad
  • 69,608
  • 17
  • 111
  • 137
user2223317
  • 211
  • 1
  • 3
  • 13
  • please post the logcat logs.... – Praful Bhatnagar Apr 01 '13 at 07:33
  • Can you also please post the value's of `firstVal.getText().toString()` and the `secondVal.getText().toString()` when the error occurs.. – Praful Bhatnagar Apr 01 '13 at 07:42
  • thanks praful..if i am giving the firstval as 10 and secondval as 5 correct answer will get and firstval as 10 and secval 10 correct answer will get and firstval as 10 and secval as 20 correct anwer 0.5 will get if firstval 10 and sec val 21 ..it will not get..the messg will appaer ..app stopped work...will come... – user2223317 Apr 01 '13 at 07:47

0 Answers0