2013-03-26 72 views
0

我正在開發Android應用程序。我試圖顯示用戶輸入,但是當我嘗試這樣做時,我收到了上述錯誤消息。我不知道我在做什麼錯。 這是我使用的代碼。謝謝。出現錯誤「Can not read row#0,col#2 from CursorWindow。Does sure your Cursor is initialized correctly。」

try { 

     Cursor cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT catgram FROM adresse_definition WHERE definition='"+word[0].toLowerCase().trim()+"'", null); 

     //Cursor cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT index_nom_adresse" + word[0].toLowerCase().trim() + " FROM adresse_definition JOIN definition ON adresse_definition.definition = definition.data_id ", null); 
     //Cursor cursor = dictionary.getDictionaryDatabase().query("adresse_definition", null, "index_nom_adresse= '" + word[0].toLowerCase().trim() + "' or definition= '" + word[0].toUpperCase().trim() + "' ", null, null, null, null); 
     cursor.moveToFirst(); 
     if (cursor.getCount() != 0) { 

      if (word[1] == null || word[1].equals("English")) { 
       translatedWord = cursor.getString(2); 
      } else { 
       translatedWord = cursor.getString(1); 
      } 
     } else { 
      translatedWord = "The word is not in database"; 
     } 
     cursor.close(); 
    } catch (SQLiteException sqle) { 
     translatedWord = "The word is not in database"; 
    } 

    dictionary.close(); 

回答

0

檢查您是否選擇您要從光標獲得的rawquery中的所有列。現在,您只需在查詢中選擇一列,然後在cursor.getString中獲取兩列。簡單地改變查詢:

Select * from table_name Where ... 
+0

幫助,謝謝。 – user2047427 2013-03-26 21:43:51

0

該代碼僅讀取遊標中的一列,並且列索引基於零。

"SELECT catgram FROM adresse_definition WHERE definition=word[0].toLowerCase().trim()"; 
+0

現在得到一個新的錯誤消息:SqliteDatabaseCpp(622):源碼返回:錯誤代碼= 1,味精=鄰近 「[0]」:語法錯誤,DB = /數據/數據/com.example.application/databases/dict.db – user2047427 2013-03-26 20:02:19

+0

我不能說任何東西,除非你發佈你的更新代碼。 – 2013-03-27 13:22:27

相關問題