Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 2 Application Development
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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)
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.