내 코드입니다 :오류 및 가까운 강제 원인이 여기에
세계적으로
TextView test;
EditText edittext;
TextWatcher watcher;
ArrayList<String> pastWrittenStrings;
에서 onCreate을 (선언)
....setcontentview etc...
test = (TextView)findViewById(R.id.textView2);
edittext = (EditText)findViewById(R.id.spokenmsg);
pastWrittenStrings = new ArrayList<String>();
watcher = new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
String writtenNoLowerCase = test.getText().toString();
pastWrittenStrings.add(writtenNoLowerCase);
if(pastWrittenStrings.size()-1 != 0){
edittext.setText(pastWrittenStrings.size()); //THIS LINE CAUSES THE ERROR
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
};
onbuttonclick (보기 V);
test.addTextChangedListener(watcher);
test.setText("calculations");
기본적으로 beforeTextChanged의 edittext 행은 오류의 원인입니다. 내가 실제로하려고하는 것은 그것이 변경되기 바로 전에 문자열 "test"의 과거 인스턴스를 기록하고 그들과 함께 arraylist를 생성하는 것입니다. 나는 결코 pastWrittenStrings에서 어떤 종류의 문자열도 얻지 못했고 모든 것을 시도해 보았습니다. arraylist를 배열로 변환했습니다.
도와주세요.
편집 : 로그 캣
07-26 21:12:26.555: E/AndroidRuntime(1580): FATAL EXCEPTION: main
07-26 21:12:26.555: E/AndroidRuntime(1580): java.lang.IllegalStateException: Could not execute method of the activity
07-26 21:12:26.555: E/AndroidRuntime(1580): Caused by: java.lang.reflect.InvocationTargetException
07-26 21:12:26.555: E/AndroidRuntime(1580): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
07-26 21:13:00.500: W/dalvikvm(1948): threadid=1: thread exiting with uncaught exception (group=0x40c67930)
07-26 21:13:00.505: E/AndroidRuntime(1948): FATAL EXCEPTION: main
07-26 21:13:00.505: E/AndroidRuntime(1948): java.lang.IllegalStateException: Could not execute method of the activity
07-26 21:13:00.505: E/AndroidRuntime(1948): Caused by: java.lang.reflect.InvocationTargetException
07-26 21:13:00.505: E/AndroidRuntime(1948): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
07-26 21:16:21.695: W/dalvikvm(2817): threadid=1: thread exiting with uncaught exception (group=0x40c67930)
07-26 21:16:21.705: E/AndroidRuntime(2817): FATAL EXCEPTION: main
07-26 21:16:21.705: E/AndroidRuntime(2817): java.lang.IllegalStateException: Could not execute method of the activity
07-26 21:16:21.705: E/AndroidRuntime(2817): Caused by: java.lang.reflect.InvocationTargetException
07-26 21:16:21.705: E/AndroidRuntime(2817): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2
포스트 로그 캣으로
CharSequence
을 허용하기 때문이다. 이 메서드 중 하나에서 .setText() 때문에 SOE가 발생하므로 StackOverflowException이라고 생각합니다. 여기를 참고하십시오 : http://stackoverflow.com/questions/7222944/changing-text-in-android-on-text-change-causes-overflow-error/7222993#7222993 귀하의 요구에 맞게 수정하십시오. –게시 됨. 실제로는 IllegalStateException입니다. –