私のプログラムでは、編集テキストボックスに数値を指定せずに計算しようとすると、プログラムがクラッシュします。値を指定すると、アプリは正常に動作します。クラッシュすると、ログ猫に次のエラーが表示されます
11-07 23:18:51.253: E/AndroidRuntime(450): FATAL EXCEPTION: main
11-07 23:18:51.253: E/AndroidRuntime(450): java.lang.NumberFormatException:
11-07 23:18:51.253: E/AndroidRuntime(450): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267)
11-07 23:18:51.253: E/AndroidRuntime(450): at java.lang.Double.parseDouble(Double.java:318)
11-07 23:18:51.253: E/AndroidRuntime(450): at com.xxx.xxx.Page1SubActivity$2.onClick(Page1SubActivity.java:77)
11-07 23:18:51.253: E/AndroidRuntime(450): at android.view.View.performClick(View.java:2485)
11-07 23:18:51.253: E/AndroidRuntime(450): at android.view.View$PerformClick.run(View.java:9080)
11-07 23:18:51.253: E/AndroidRuntime(450): at android.os.Handler.handleCallback(Handler.java:587)
11-07 23:18:51.253: E/AndroidRuntime(450): at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 23:18:51.253: E/AndroidRuntime(450): at android.os.Looper.loop(Looper.java:123)
11-07 23:18:51.253: E/AndroidRuntime(450): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-07 23:18:51.253: E/AndroidRuntime(450): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 23:18:51.253: E/AndroidRuntime(450): at java.lang.reflect.Method.invoke(Method.java:507)
11-07 23:18:51.253: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-07 23:18:51.253: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-07 23:18:56.723: I/Process(450): Sending signal. PID: 450 SIG: 9
これがJavaコードです。
ImageButton rightbuton = (ImageButton) findViewById(R.id.rightbutton);
rightbuton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
edit1 = (EditText) findViewById(R.id.editText1);
edit2 = (EditText) findViewById(R.id.editText2);
textview = (TextView) findViewById(R.id.textView5);
Double number2 = 0.0;
Double number3 = 0.0;
if (edit1.getText().toString().trim().length()>0 ) {
number2 = Double
.parseDouble(edit1.getText().toString());
}
if(edit2.getText().toString().trim().length()>0){
number3 = Double
.parseDouble(edit2.getText().toString());
}
number3 = number2 * number3;
int number2int = (int) (number2 * number3);
int number3int = (int) (number3 / 40);
number2 = number2 * number3;
number3 = number3 / 40;
if (number2int - number2 != 0) {
String number2val = Double.toString(number2);
textview.setText(number2val);
} else {
String number2val = Integer.toString(number2int);
textview.setText(number2val);
// label.text = [NSString stringWithFormat:@"%d",
// number2int];
}
if (number3int - number3 != 0) {
String number3val = Double.toString(number3);
textview.setText(number3val);
} else {
String number3val = Integer.toString(number3int);
textview.setText(number3val);
}
}
});