简体   繁体   English

在Android中阅读电话簿中的联系人

[英]Reading contacts from phone book in Android

I 'm trying to read and display contacts from phone book in android. 我正在尝试从android中的电话簿中读取和显示联系人。 My Device is synced up with gmail and funambol which togehter have more than 600 records. 我的设备已与gmail和funambol同步,总共有600多个记录。 Now by default my application reads gmail contacts. 现在默认情况下,我的应用程序读取gmail联系人。 On selecting any contact from the displayed list, it throws an exception as the list is displaying a gmail contact which just has email and no phone no. 从显示的列表中选择任何联系人时,由于列表显示的是仅包含电子邮件且没有电话号码的gmail联系人,因此会引发异常。

I need phone no to use in my application. 我需要电话号码才能在我的应用程序中使用。

thanks 谢谢

Take a look at this answer here . 这里看看这个答案 It provides all the detail you need to get the contacts right. 它提供了正确联系所需的所有详细信息。

The reason for the crash might be because you are trying to read the phone number when there is none, causing a NullPointerException. 崩溃的原因可能是因为您尝试在没有电话号码的情况下读取电话号码,从而导致NullPointerException。 Maybe check if it's null before you try and use it, and if it is null then ask the user to pick again. 尝试使用它之前,也许先检查它是否为空,如果它为空,则请用户再次选择。

If this isn't right, feel free to provide more detail like code and logcat logs. 如果这样做不合适,请随时提供更多详细信息,例如代码和logcat日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM