I recently upgraded Android Studio to Arctic Fox | 2020.3.1 Patch 2. Whenever I use this code, it is highlighted as error (red underlines).
cursor.getColumncursor.getString(cursor.getColumnIndex(DataContract.WeightEntry.COLUMN_SYNC_STATUS));
Screenshot of highlighted code:
This is found in all the places where the getColumnIndex() function is used.
However, even if code is highlighted as an error, the compiler shows build success and the code runs fine.
Problem: Due to red underlines, it is causing a bad coding experience. I would like to know if this is a bug or something is wrong with my Android Studio settings. I have tried steps like:
- Importing project again
- Invalidating caches and restart
- Deleting .idea folder to reset settings
2
Answers
This is a known issue, right click and from the context actions select Suppress which will add
@SuppressLint("Range")
(easiest fix/get-around).The
@Suppress("Range")
can be placed at various levels of scope you can also use Analyze/Inspect Code and edit the profile e.g.To then find the respective code filter on the warning e.g. Range in this case :-
Refer to https://developer.android.com/studio/write/lint
Just replace
cursor.getColumncursor.getString(cursor.getColumnIndex(DataContract.WeightEntry.COLUMN_SYNC_STATUS));
as
cursor.getColumncursor.getString(cursor.getColumnIndexOrThrow(DataContract.WeightEntry.COLUMN_SYNC_STATUS));