誰かが私のコードをチェックできますか?TextView
とを使用してスコアの計算を行ってEditText
います。変数の整数も宣言しましたが、コードを実行すると、整数の解析時にエラーが発生します。前もって感謝します。詳細については、私のログ猫も確認してください。これが私のコードです:
initControls();
}
private void initControls()
{
amount1=(EditText)findViewById(R.id.amount1);
amount2=(EditText)findViewById(R.id.amount2);
amount3=(EditText)findViewById(R.id.amount3);
result=(TextView)findViewById(R.id.result);
calculate=(Button)findViewById(R.id.finish);
calculate.setOnClickListener(new Button.OnClickListener()
{public void onClick
(View v) { calculate();}});
}
private void calculate()
{
if(amount1.getText().toString().equals(null))
{
x=0;
}
else
amount1.getText().toString();
x=Integer.parseInt(amount1.getText().toString());
if(amount2.getText().toString().equals(null)) {
y=0;
}
else
amount2.getText().toString();
y=Integer.parseInt(amount2.getText().toString());
if(amount3.getText().toString().equals(null)) {
v=0;
}
else
amount3.getText().toString();
v=Integer.parseInt(amount3.getText().toString());
{
z=x+y+v;
result.setText(Integer.toString(z));
}
これが私のログ猫です:
08-16 16:15:51.794: W/dalvikvm(224): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-16 16:15:51.794: E/AndroidRuntime(224): Uncaught handler: thread main exiting due to uncaught exception
08-16 16:15:51.824: E/AndroidRuntime(224): java.lang.NumberFormatException: unable to parse '' as integer
08-16 16:15:51.824: E/AndroidRuntime(224): at java.lang.Integer.parseInt(Integer.java:353)
08-16 16:15:51.824: E/AndroidRuntime(224): at java.lang.Integer.parseInt(Integer.java:323)
08-16 16:15:51.824: E/AndroidRuntime(224): at drj.thesis.tridi.Maingame.calculate(Maingame.java:70)
08-16 16:15:51.824: E/AndroidRuntime(224): at drj.thesis.tridi.Maingame.access$0(Maingame.java:54)
08-16 16:15:51.824: E/AndroidRuntime(224): at drj.thesis.tridi.Maingame$1.onClick(Maingame.java:52)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.View.performClick(View.java:2364)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.View.onTouchEvent(View.java:4179)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.widget.TextView.onTouchEvent(TextView.java:6541)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.View.dispatchTouchEvent(View.java:3709)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-16 16:15:51.824: E/AndroidRuntime(224): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-16 16:15:51.824: E/AndroidRuntime(224): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.os.Looper.loop(Looper.java:123)
08-16 16:15:51.824: E/AndroidRuntime(224): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-16 16:15:51.824: E/AndroidRuntime(224): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 16:15:51.824: E/AndroidRuntime(224): at java.lang.reflect.Method.invoke(Method.java:521)
08-16 16:15:51.824: E/AndroidRuntime(224): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-16 16:15:51.824: E/AndroidRuntime(224): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-16 16:15:51.824: E/AndroidRuntime(224): at dalvik.system.NativeStart.main(Native Method)
08-16 16:15:51.857: I/dalvikvm(224): threadid=7: reacting to signal 3
08-16 16:15:51.864: E/dalvikvm(224): Unable to open stack trace file '/data/anr/traces.txt': Permission denied