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)