-2

这里有什么问题导致异常发生?我在这里没有发现任何问题。任何人都可以看看这个:

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;
}
4

1 回答 1

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 android.view.ViewRootImpl@40d81208 
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 列,与上述不匹配

文档

返回给定列名的从零开始的索引,如果该列不存在,则返回 -1。如果您希望该列存在,请改用 getColumnIndexOrThrow(String) ,这将使错误更加清晰。


编辑

尝试这个:

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

然后将您的新问题粘贴LogCat到您的问题中。

于 2013-05-09T04:39:21.090 回答