我开发了一个简单的计算器..一切都运行良好...计算器将添加mul sub和div两个数字问题是除法部分..如果第一个数字大于第二个数字,则其他工作正常应用程序会意外停止msg会来......我现在只是给我的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());
}
});
这是我的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)