android-获取联系电话

android-获取联系电话,第1张

概述我在获取联系电话时遇到麻烦,我在日志猫说中一直出错02-2419:40:42.772:ERROR/CursorWindow(21467):Badrequestforfieldslot0,-1.numRows=1,numColumns=24这是我的代码importandroid.app.Activity;importandroid.content.ContentResolver;importandroid.c

我在获取联系电话时遇到麻烦,我在日志猫说中一直出错

02-24 19:40:42.772: ERROR/CursorWindow(21467): Bad request for fIEld slot 0,-1. numRows = 1, numColumns = 24

这是我的代码

import androID.app.Activity;import androID.content.ContentResolver;import androID.content.Intent;import androID.database.Cursor;import androID.net.Uri;import androID.provIDer.ContactsContract;import androID.provIDer.ContactsContract.CommonDataKinds.Phone;import androID.util.Log;import androID.vIEw.VIEw;import androID.Widget.ListVIEw;import androID.Widget.button;import androID.Widget.SimpleCursorAdapter;import androID.os.Bundle;public class Contacts extends Activity {private ListVIEw mContactList;private button mAddContact;private boolean mShowInvisible = false;boolean set;public String name = "";public String ID;public String phone;@OverrIDepublic voID onCreate(Bundle savedInstanceState){    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.contact_ListvIEw);    mContactList = (ListVIEw) findVIEwByID(R.ID.contactList);    mAddContact = (button) findVIEwByID(R.ID.addContactbutton);    mAddContact.setonClickListener(new VIEw.OnClickListener(){        @OverrIDe        public voID onClick(VIEw v) {            Intent i = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);            startActivityForResult(i,1);        }    });}public voID onActivityResult(int requestCode, int resultCode, Intent data){    if(resultCode == RESulT_OK){                getContactData(data);        }    }    public voID getContactData(Intent data){    ContentResolver cr = getContentResolver();    Uri contactData = data.getData();    Log.v("Contact", contactData.toString());    Cursor c = managedquery(contactData,null,null,null,null);    if(c.movetoFirst()){            ID = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));        Log.v("Contact", "ID: " + ID.toString());            name = c.getString(c.getColumnIndex(ContactsContract.Contacts.disPLAY_name));        Log.v("Contact", "name: " + name.toString());        if (Integer.parseInt(c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {                Cursor pCur = cr.query(Phone.CONTENT_URI,null,Phone.CONTACT_ID +" = ?", new String[]{ID}, null);          while(pCur.movetoNext()){              phone = c.getString(c.getColumnIndex(Phone.NUMBER));              Log.v("getting phone number", "Phone Number: " + phone);          }      }    }}

一切正常,直到我尝试获取电话号码为止

解决方法:

不应该是:

while(pCur.movetoNext()){   phone = pCur.getString(pCur.getColumnIndex(Phone.NUMBER));   Log.v("getting phone number", "Phone Number: " + phone);}

也就是说,使用pCur而不是“ c”光标来保存联系人?

总结

以上是内存溢出为你收集整理的android-获取联系电话全部内容,希望文章能够帮你解决android-获取联系电话所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1092762.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存