我在 SO 上看到过关于同一问题的问题,但没有一个问题得到公认的答案。
究竟是什么错误通知?为什么会出现这种情况?
我的应用程序中的游标很少,我确实在他们的工作完成后关闭了它们。但是错误仍然出现。可能是什么原因?
这是代码:::
private String fetchContactIdFromPhoneNumber(String phoneNumber) {
// TODO Auto-generated method stub
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phoneNumber));
Cursor cFetch = getContentResolver().query(uri,
new String[] { PhoneLookup.DISPLAY_NAME, PhoneLookup._ID },
null, null, null);
String contactId = "";
if (cFetch.moveToFirst()) {
cFetch.moveToFirst();
contactId = cFetch.getString(cFetch
.getColumnIndex(PhoneLookup._ID));
}
//System.out.println(contactId);
if(cFetch != null)
{
cFetch.close();
}
return contactId;
}
public Uri getPhotoUri(long contactId) {
ContentResolver contentResolver = getContentResolver();
Cursor cursor;
try {
cursor = contentResolver
.query(ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.CONTACT_ID
+ "="
+ contactId
+ " AND "
+ ContactsContract.Data.MIMETYPE
+ "='"
+ ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
+ "'", null, null);
if (cursor != null) {
if (!cursor.moveToFirst()) {
return null; // no photo
}
} else {
return null; // error in cursor process
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
if(cursor != null)
{
cursor.close();
}
Uri person = ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, contactId);
return Uri.withAppendedPath(person,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
}
这是我使用游标的代码。我还有一个 contentresolver 对象。我也应该关闭它吗?
最后,这个错误对应用程序有什么影响,因为它似乎并没有中断应用程序的执行。