Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 2 Application Development
|
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2010, 04:39 PM
Registered User
 
Join Date: Mar 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 10/Live Folder - UriMatcher not performing as expected.

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.
 
Old June 4th, 2010, 05:52 PM
Registered User
 
Join Date: Mar 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default case counts (like I didn't know this)

It's
Code:
com.paad.provider.earthquake
not

Code:
com.paad.provider.Earthquake
in the static initializer. So the correct code for the initializer is:

Code:
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)
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10, listing 10-10-app kiwibrit BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 2 August 18th, 2009 04:21 AM
Chapter 10 JimSchubert BOOK: Ruby on Rails for Microsoft Developers 1 May 17th, 2009 11:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.