Reputation: 195
I am trying to retrieve rows of locations from my SQLiteTable but I ran into a compilation error, the constructor CursorLoader is undefined.
@Override
public Loader<Cursor> onCreateLoader(int arg0,
Bundle arg1) {
// Uri to the content provider LocationsContentProvider
Uri uri = LocationsContentProvider.CONTENT_URI;
// Fetches all the rows from locations table
//return new CursorLoader(null);
//(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
/ERROR HERE
return new CursorLoader(this, null, null, null, null);
}
In LocationsContentProvider.java
/** A callback method which is invoked by default content uri */
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if(uriMatcher.match(uri)==LOCATIONS){
return mLocationsDB.getAllLocations();
}
return null;
}
Upvotes: 0
Views: 139
Reputation: 11948
Cursor Loader constructor get following property :
public CursorLoader(Context context, Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
super(context);
mObserver = new ForceLoadContentObserver();
mUri = uri;
mProjection = projection;
mSelection = selection;
mSelectionArgs = selectionArgs;
mSortOrder = sortOrder;
}
you miss one property. you can add one null
or define your order and pass to the constructor.
and as CommonsWar said, you must pass your URI
as a second argument,
Upvotes: 1
Reputation: 1007554
CursorLoader
does not have a five-parameter constructor. More importantly, you need to provide the Uri
pointing to the collection on the ContentProvider
that you are trying to query. You are welcome to say that the final four parameters are null
, but add the Uri
as the second parameter to the constructor.
You may wish to read the documentation for the six-parameter CursorLoader
constructor that you will be using.
Also note that the code in your first code snippet will not compile, as you are missing a comma between two of the null
values.
Upvotes: 1