I just stumbled upon the same issue due to the user crash message I received today for my application. If the Android documentation is unclear about something, it helps to look at the source code. Here is what I found about the reasons for returning ContentResolver.query() null :
Content provider cannot be purchased. This may be due to a problem with the specified Uri or because it simply does not exist on the system. If Uri is a problem, the reasons are as follows: the protocol is not content:// , or Uri does not have part of the authorization string (Uri.getAuthority () == null).
The request method received by the provider itself returns null .
A content provider might have been purchased, but a RemoteException was thrown during the request.
Especially because of (2.) it is rather arbitrary, which may be the reason for null as a result, since there are no rules. But usually, if SQLite is the back-end of the ContentProvider , you can expect at least some kind of empty Cursor instead of a null result.
The ContentProvider Android system performs some checks before they return anything. If the input is not as expected, the likelihood that null can be returned is unlikely. But honestly, this has never happened to me before. I usually get an IllegalArgumentException in case of problems with the request parameters. Perhaps some ContentProvider implementations return null in the case of empty result sets.
Anyway. It seems necessary to always check for null . Especially, for example, the reason number (3.) is what can happen on any Android device.
tiguchi Apr 19 '13 at 15:43 2013-04-19 15:43
source share