这是对 EditText 表中输入的值进行检查的一段代码,如果我输入的值有误,请正确显示 alertdialog,我更正输入,再次按下按钮完成输入和应用程序崩溃,为什么?
button = new Button(this);
button.setText("Riempi la prima Matrice");
tableLayout.addView(button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
try {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
array[t] = Double.parseDouble(values[i][j].getText().toString());
t++;
}
}
}
catch (NumberFormatException nfe) {
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(SecondaAttivita.this);
builder.setTitle("Error");
builder.setMessage("Wrong input format");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
});
builder.show();
}
}
});
这是一个 logCat
FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException
it.bisemanuDEV.prodMatrix.SecondaAttivita$1.onClick(SecondaAttivita.java:96)
android.view.View.performClick(View.java:2408)
android.view.View$PerformClick.run(View.java:8816)
android.os.Handler.handleCallback(Handler.java:587)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:123)
android.app.ActivityThread.main(ActivityThread.java:4627)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:521)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
dalvik.system.NativeStart.main(Native Method)