0

我开发了一个简单的计算器..一切正常...计算器将添加 mul sub 和 div 两个数字问题在于除法部分..如果第一个数字大于第二个数字,t 将正常工作,否则应用程序将意外停止 味精会来...我现在只是给我的 div 代码...

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());
    }
});

这是我的日志猫

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)
4

0 回答 0