我遇到了一个错误,principal==0.0
我不明白为什么会这样。
if(et1.getText()!=null) {
try {
principal = Double.valueOf(et1.getText().toString());
}
catch(Exception e) {
message = "Incorrect value";
}
}
// The problem is in the if statement below!
if(principal==0.00) {
message = "value cannot be zero";
title = "error";
}
我得到的错误如下:
01-31 22:21:37.700: E/AndroidRuntime(985): FATAL EXCEPTION: main
01-31 22:21:37.700: E/AndroidRuntime(985):
java.lang.NullPointerException 01-31 22:21:37.700:
E/AndroidRuntime(985): at
com.compoundinterest.MainActivity$1.onClick(MainActivity.java:65)
01-31 22:21:37.700: E/AndroidRuntime(985): at
android.view.View.performClick(View.java:2485) 01-31 22:21:37.700:
E/AndroidRuntime(985): at
android.view.View$PerformClick.run(View.java:9080) 01-31
22:21:37.700: E/AndroidRuntime(985): at
android.os.Handler.handleCallback(Handler.java:587) 01-31
22:21:37.700: E/AndroidRuntime(985): at
android.os.Handler.dispatchMessage(Handler.java:92) 01-31
22:21:37.700: E/AndroidRuntime(985): at
android.os.Looper.loop(Looper.java:123) 01-31 22:21:37.700:
E/AndroidRuntime(985): at
android.app.ActivityThread.main(ActivityThread.java:3683) 01-31
22:21:37.700: E/AndroidRuntime(985): at
java.lang.reflect.Method.invokeNative(Native Method)
这个错误的原因可能是什么,我该如何解决?