2013-05-09 128 views
-2

這裏有什麼問題導致異常發生?我沒有在這裏找到任何問題。任何人都可以看看這個:根據您的堆棧跟蹤錯誤:無法讀取第0行,第-1列。 weired

private Cursor getAllPhoneNumbersForNamesLike(String str){ 
    Cursor tempContact=null; 
    tempContact=this.getContentResolver().query(uriContact,null,"display_name like ?",new String[]{tokenLike+"%"},null); 
    if(tempContact!=null && tempContact.getCount()>0){ 
     try{ 
      tempContact.moveToFirst(); 
      Toast.makeText(this,tempContact.getString(tempContact.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)), Toast.LENGTH_LONG).show(); 
     }catch(Exception e){ 
      Toast.makeText(this, "Inside getAllPhoneNumbersForNamesLike catch: "+e.toString(), Toast.LENGTH_LONG).show(); 
      return null; 
     } 
     return this.getContentResolver().query(uriSmsRead,null,inClause,null,null); 
    } 
    else 
     return null; 
} 
+0

private Uri uriContact = ContactsContract.Contacts.CONTENT_URI; – 2013-05-09 04:13:52

+0

給我們提供錯誤和堆棧跟蹤。 – Patashu 2013-05-09 04:14:04

+0

String tokenLike =「SJ」 – 2013-05-09 04:14:26

回答

1

05-09 04:15:42.888: D/InputEventConsistencyVerifier(3668): KeyEvent: ACTION_UP but key was not down. 
05-09 04:15:42.888: D/InputEventConsistencyVerifier(3668): in [email protected] 
05-09 04:15:42.888: D/InputEventConsistencyVerifier(3668): 0: sent at 22940735000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_ENTER, scanCode=28, metaState=0, flags=0x8, repeatCount=0, eventTime=22940735, downTime=22940633, deviceId=0, source=0x101 } 
05-09 04:15:45.408: E/CursorWindow(3668): Failed to read row 0, column -1 from a CursorWindow which has 3 rows, 29 columns 

你需要考慮你的

tempContact.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER) 

聽起來像是你的29列中,不符合以上條件

Documentation

Returns the zero-based index for the given column name, or -1 if the column doesn't exist. If you expect the column to exist use getColumnIndexOrThrow(String) instead, which will make the error more clear.


編輯

試試這個:

getColumnIndexOrThrow((ContactsContract.CommonDataKinds.Phone.NUMBER)) 

然後貼上新LogCat在你的問題。

+0

但ContactsContract.CommonDataKinds.Phone.NUMBER是ContactsContract.CommonDataKinds.Phone.CONTENT_URI的正確列名稱 – 2013-05-09 04:58:21

+0

沒有前導或尾隨空格嗎?案例分歧?任何可能不同的小東西? – jnthnjns 2013-05-09 05:00:34

+0

我明白Asok ..這是因爲它是 – 2013-05-09 05:03:39

相關問題