何時間もの調査とテストの後、これを呼び出すとアプリがクラッシュする理由を理解できませんでした
inputLocation.setText(""); inputLocation.setText(null);
これで問題なく動作します:
inputLocation.setText("your text");
また
inputLocation.setText(editText.getText().toString());
等
どんな助けでも大歓迎です。ありがとう。
inputLocation.addTextChangedListener
// / Execute code without the use of the save changes button.
// ///////////////////////////////////////////
inputLocation.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
/* Process to check type */
String location_string = inputLocation.getText().toString();
String first_location_char = location_string.substring(0, 1);
if (inputLocation.getText().toString().length() == locationsize) {
String last_location_char = location_string.substring(8);
if (last_location_char.equals("L")
&& first_location_char.equals("L")) {
inputLocation.setText(location_string.substring(1, 8),
TextView.BufferType.EDITABLE);
new UpdateLocation().execute();
} else if (!first_location_char.isEmpty()
&& !last_location_char.isEmpty()) {
alertDialog = new AlertDialog.Builder(
CheckLocationActivity.this).create();
alertDialog.setTitle("Wrong Code for Location");
alertDialog
.setMessage("Please scan one more time the correct barcode!");
alertDialog.setButton(-1, getString(R.string.Ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
inputLocation.setText("",
TextView.BufferType.EDITABLE);
}
});
/*
* alertDialog.setButton(-2, getString(R.string.No), new
* DialogInterface.OnClickListener() {
*
* @Override public void onClick(DialogInterface dialog,
* int which) { // do nothing dialog will dismiss } });
*/
alertDialog.show();
}
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
}
});
// / Execute code without the use of the save changes button.
// ///////////////////////////////////////////
コードセクション
alertDialog = new AlertDialog.Builder(
CheckLocationActivity.this).create();
alertDialog.setTitle("Wrong Code for Location");
alertDialog
.setMessage("Please scan one more time the correct barcode!");
alertDialog.setButton(-1, getString(R.string.Ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
inputLocation.setText("",
TextView.BufferType.EDITABLE);
}
});
/*
* alertDialog.setButton(-2, getString(R.string.No), new
* DialogInterface.OnClickListener() {
*
* @Override public void onClick(DialogInterface dialog,
* int which) { // do nothing dialog will dismiss } });
*/
alertDialog.show();
ログファイル
11-05 16:41:33.638: W/dalvikvm (19191): threadid=1: キャッチされない例外で終了するスレッド (グループ = 0x41513700) 11-05 16:41:33.648: E/AndroidRuntime(19191): 致命的な例外: メイン 11-05 16:41:33.648: E/AndroidRuntime (19191): java.lang.StringIndexOutOfBoundsException: 長さ = 0; regionStart=0; regionLength=1 11-05 16:41:33.648: E/AndroidRuntime (19191): java.lang.String.startEndAndLength (String.java:583) で 11-05 16:41:33.648: E/AndroidRuntime(19191): java.lang.String.substring(String.java:1464) で 11-05 16:41:33.648: E/AndroidRuntime (19191): com.dev.assetlocation.CheckLocationActivity$3.onTextChanged (CheckLocationActivity.java:162) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.widget.TextView.sendOnTextChanged (TextView.java:7318) で 11-05 16:41:33.648: E/AndroidRuntime(19191): android.widget.TextView.setText(TextView.java:3774) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.widget.TextView.setText (TextView.java:3629) で 11-05 16:41:33.648: E/AndroidRuntime(19191): android.widget.EditText.setText(EditText.java:80) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.widget.TextView.setText (TextView.java:3604) で 11-05 16:41:33.648: E/AndroidRuntime (19191): com.dev.assetlocation.CheckLocationActivity$2.onTextChanged (CheckLocationActivity.java:103) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.widget.TextView.sendOnTextChanged (TextView.java:7318) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.widget.TextView.handleTextChanged (TextView.java:7377) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.widget.TextView$ChangeWatcher.onTextChanged (TextView.java:9076) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.text.SpannableStringBuilder.sendTextChanged (SpannableStringBuilder.java:962) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.text.SpannableStringBuilder.replace (SpannableStringBuilder.java:496) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.text.SpannableStringBuilder.replace (SpannableStringBuilder.java:435) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.text.SpannableStringBuilder.replace (SpannableStringBuilder.java:30) で 11-05 16:41:33.648: E/AndroidRuntime(19191): android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:673) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.view.inputmethod.BaseInputConnection.commitText (BaseInputConnection.java:197) で 11-05 16:41:33.648: E/AndroidRuntime (19191): com.android.internal.widget.EditableInputConnection.commitText (EditableInputConnection.java:183) で 11-05 16:41:33.648: E/AndroidRuntime (19191): com.android.internal.view.IInputConnectionWrapper.executeMessage (IInputConnectionWrapper.java:279) で 11-05 16:41:33.648: E/AndroidRuntime (19191): com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage (IInputConnectionWrapper.java:77) で 11-05 16:41:33.648: E/AndroidRuntime (19191): android.os.Handler.dispatchMessage (Handler.java:99) で 11-05 16:41:33.648: E/AndroidRuntime(19191): android.os.Looper.loop(Looper.java:137) 11-05 16:41:33.648: E/AndroidRuntime (19191): android.app.ActivityThread.main (ActivityThread.java:5103) で 11-05 16:41:33.648: E/AndroidRuntime(19191): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) で 11-05 16:41:33.648: E/AndroidRuntime(19191): java.lang.reflect.Method.invoke(Method.java:525) で 11-05 16:41:33.648: E/AndroidRuntime (19191): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:737) で 11-05 16:41:33.648: E/AndroidRuntime (19191): com.android.internal.os.ZygoteInit.main (ZygoteInit.java:553) で 11-05 16:41:33.648: E/AndroidRuntime(19191): dalvik.system.NativeStart.main(ネイティブ メソッド) で 11-05 16:41:36.201: D/libEGL(19240): ロードされた /system/lib/egl/libEGL_adreno200.so 11-05 16:41:36.201: D/libEGL(19240): ロードされた /system/lib/egl/libGLESv1_CM_adreno200.so 11-05 16:41:36.201: D/libEGL(19240): ロードされた /system/lib/egl/libGLESv2_adreno200.so 11-05 16:41:36.211: I/Adreno200-EGL(19240): : EGL 1.4 QUALCOMM ビルド: Iabe52cfaeae4c5fab1acacfe6f056ba15fa93274 11-05 16:41:36.241: D/OpenGLRenderer(19240): デバッグ モードを有効にしています 0