Textwatcherインターフェイスを実装しようとしましたが、のテキストを変更しようとしていますがafterTextChanged()
、クラッシュします。なぜこれがクラッシュするのですか?:
@Override
public void afterTextChanged(Editable s) {
Editable myText;
if(s.toString().contains("hi")){
myText = s.append(" ho");
myEdit.setText(myText);
}
}
Logcat
01-27 01:23:18.213: E/AndroidRuntime(2563): FATAL EXCEPTION: main
01-27 01:23:18.213: E/AndroidRuntime(2563): java.lang.StackOverflowError
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.graphics.Paint.getTextRunAdvances(Paint.java:1720)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.MeasuredText.addStyleRun(MeasuredText.java:164)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.MeasuredText.addStyleRun(MeasuredText.java:204)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.StaticLayout.generate(StaticLayout.java:281)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.DynamicLayout.reflow(DynamicLayout.java:284)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.DynamicLayout.access$000(DynamicLayout.java:35)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:621)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.DynamicLayout$ChangeWatcher.onTextChanged(DynamicLayout.java:631)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:962)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:496)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:247)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:30)
01-27 01:23:18.213: E/AndroidRuntime(2563): at com.example.textfields.MainActivity$1.afterTextChanged(MainActivity.java:45)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView.sendAfterTextChanged(TextView.java:7108)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8805)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:970)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:497)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:247)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:30)
01-27 01:23:18.213: E/AndroidRuntime(2563): at com.example.textfields.MainActivity$1.afterTextChanged(MainActivity.java:45)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView.sendAfterTextChanged(TextView.java:7108)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8805)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:970)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:497)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:247)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:30)
01-27 01:23:18.213: E/AndroidRuntime(2563): at com.example.textfields.MainActivity$1.afterTextChanged(MainActivity.java:45)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView.sendAfterTextChanged(TextView.java:7108)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8805)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:970)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:497)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:247)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:30)
01-27 01:23:18.213: E/AndroidRuntime(2563): at com.example.textfields.MainActivity$1.afterTextChanged(MainActivity.java:45)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView.sendAfterTextChanged(TextView.java:7108)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8805)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:970)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:497)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:247)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:30)
01-27 01:23:18.213: E/AndroidRuntime(2563): at com.example.textfields.MainActivity$1.afterTextChanged(MainActivity.java:45)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView.sendAfterTextChanged(TextView.java:7108)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8805)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:970)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:497)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:247)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.append(SpannableStringBuilder.java:30)
01-27 01:23:18.213: E/AndroidRuntime(2563): at com.example.textfields.MainActivity$1.afterTextChanged(MainActivity.java:45)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView.sendAfterTextChanged(TextView.java:7108)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8805)
01-27 01:23:18.213: E/AndroidRuntime(2563): at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:970)