데이터베이스에서 해당 정보를 가져 오는 스피너에서 문자열을 가져 오려고합니다. 사용시안드로이드 : MySQL 데이터베이스 커서로 인해 IllegalStateException이 발생 함 (CursorWindow에서 행 *, 열 *을 읽지 못했습니다.)
spinner.getSelectedItem().toString();
나는 "[email protected]"과 같은 문자열을 얻습니다. 해결 된 문자열을 얻으려면 커서를 사용하여 데이터베이스를 쿼리하려고했지만 LogCat의 메시지에 "3 행 2 열을 가진 CursorWindow에서 행 1, 열 2를 읽지 못했습니다."라는 메시지가 나타나는 동안 IllegalStatException이 발생합니다.
행과 열의 숫자는 정확한 셀이어야하며 조회 할 값이 들어 있습니다.
저는 여기에 사용되는 코드는 다음과 같습니다
int selection = (int) spinner.getSelectedItemId(); //I get the selected item id.
Cursor selectioncursor = db.getAllSubjects(); //This is a query getting all the contents from the table
selectioncursor.moveToPosition(selection); //The id I got earlier equals the number of the row, the data is stored in, so I move the cursor to the correct row.
String subject = selectioncursor.getString(2); //Now the cursor should get the string from column 2 which is the one containing all the values (first column is "_id" of course)
당신의 도움에 대한 감사합니다.
나는 당신에게 한 가지 제안을 할 수 있습니다. 2 열의 값을 원하면 selectioncursor.getString (1);을 쿼리해야합니다. selectioncursor.getString (2)가 아닙니다. 커서 인덱스가 0.부터 시작하기 때문에 logcat을 게시하십시오. –
@SharathG 이미 내 문제를 해결했습니다. 고마워요 :) – BlueHazard
아, 그게 이미 자신이 해결 한 것을 듣기 좋다. 건배 –