Reputation: 74066
I always see people say that it cursor is never null so you dont need to check for null or not but then there are other people that say that cursor can be null and you chould always check it.
so looking at the query method here it does show that null gets returned so I dont know if I am just missing something or are the people saying that cursor is never null wrong?
do you or do you not need to check if Cursor
is null when a query is made?
Upvotes: 4
Views: 1423
Reputation: 5302
SQliteDatabase.query() returns a Cursor object, which is positioned before the first entry. Cursor is never null but it can be empty.
For ContentResolver queries
it can be null. Check this SO question.
Upvotes: 1
Reputation: 152927
For ContentResolver
queries, yes, the returned Cursor
can be null
as illustrated by the code you linked.
For SQLiteDatabase
queries, no, checking for null
Cursor
is not necessary. Though it does not hurt much.
Upvotes: 8
Reputation: 2976
Be safe and make your code solid, check for null. You can refer to this code from Android. As we can see it is possible to get null.
Upvotes: 0