You need to move your Cursor at first position. By default the cursor set at -1 index, so moving it to 0th position you need to use moveToFirst().
So you can modify your code like
Cursor c = context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,projection,selection,selectionArgs , null);
if (c.moveToFirst()) {
int rawContactId=c.getInt(c.getColumnIndex(ContactsContract.RawContacts._ID));
}