Fix Cursor warnings

This commit is contained in:
xynngh 2021-07-31 21:14:56 +04:00
parent 0198c99a1c
commit 1d6e475eb5
2 changed files with 7 additions and 7 deletions

View File

@ -60,11 +60,11 @@ public class CallLogHelper {
try (Cursor cursor = context.getContentResolver() try (Cursor cursor = context.getContentResolver()
.query(uri, QUERY_PROJECTION, selection, selectionArgs, sortOrder)) { .query(uri, QUERY_PROJECTION, selection, selectionArgs, sortOrder)) {
if (cursor != null) { if (cursor != null) {
int idIndex = cursor.getColumnIndex(CallLog.Calls._ID); int idIndex = cursor.getColumnIndexOrThrow(CallLog.Calls._ID);
int typeIndex = cursor.getColumnIndex(CallLog.Calls.TYPE); int typeIndex = cursor.getColumnIndexOrThrow(CallLog.Calls.TYPE);
int numberIndex = cursor.getColumnIndex(CallLog.Calls.NUMBER); int numberIndex = cursor.getColumnIndexOrThrow(CallLog.Calls.NUMBER);
int dateIndex = cursor.getColumnIndex(CallLog.Calls.DATE); int dateIndex = cursor.getColumnIndexOrThrow(CallLog.Calls.DATE);
int durationIndex = cursor.getColumnIndex(CallLog.Calls.DURATION); int durationIndex = cursor.getColumnIndexOrThrow(CallLog.Calls.DURATION);
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
long id = cursor.getLong(idIndex); long id = cursor.getLong(idIndex);

View File

@ -27,9 +27,9 @@ public class ContactsHelper {
try (Cursor cursor = resolver.query(uri, PROJECTION, null, null, null)) { try (Cursor cursor = resolver.query(uri, PROJECTION, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
ContactItem contact = new ContactItem( ContactItem contact = new ContactItem(
cursor.getLong(cursor.getColumnIndex( cursor.getLong(cursor.getColumnIndexOrThrow(
ContactsContract.Contacts._ID)), ContactsContract.Contacts._ID)),
cursor.getString(cursor.getColumnIndex( cursor.getString(cursor.getColumnIndexOrThrow(
ContactsContract.Contacts.DISPLAY_NAME)) ContactsContract.Contacts.DISPLAY_NAME))
); );