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 オブジェクトもあります。それも閉めたほうがいいですか?
そして最後に、このエラーがアプリケーションに与える影響は何ですか。アプリケーションの実行を中断しているようには見えないからです。