The UriMatcher conditional in EarthquakeProvider.query() method is not matching the uri parameter when the Live Folder is selected/clicked from the desktop.
Code:
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(EARTHQUAKE_TABLE);
// If this is a row query, limit the result set to the passed in row.
switch (uriMatcher.match(uri)) {
case QUAKE_ID:
queryBuilder.appendWhere(KEY_ID + "=" + uri.getPathSegments().get(1));
break;
case LIVE_FOLDER:
queryBuilder.setProjectionMap(LIVE_FOLDER_PROJECTION);
break;
default:
break;
}
Since no one else is having problems I've checked and rechecked the code comparing it with the download version. I've set break points on the static initializer to make sure the code was being executed. Here is the initialization code:
Code:
private static final int QUAKES = 1;
private static final int QUAKE_ID = 2;
private static final int LIVE_FOLDER = 3;
private static final UriMatcher uriMatcher;
// Allocate the UriMatcher object, where a URI ending in "earthquakes' will
// correspond to a request for all earthquakes, and "earthquakes' with a
// trailing '/[rowID]' will represent a single earthquake row.
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.paad.provider.Earthquake", "earthquakes", QUAKES);
uriMatcher.addURI("com.paad.provider.Earthquake", "earthquakes/#", QUAKE_ID);
uriMatcher.addURI("com.paad.provider.Earthquake", "live_folder", LIVE_FOLDER);
}
When the uri = content://com.paad.provider.earthquake/live_folder the
Code:
uriMatcher.match(uri)
is returning -1, which later results in a failed query to the database. I've inspected the uriMatcher at the breakpoint and the ArrayList within doesn't look correct.
Any clues? Since I've been staring at the code for so long I'm sure I'm missing something. Any help would be appreciated. Thanks.