01 Feb 2009, 16:45
Generic-user-small

Attila Csordas (2 posts)

Hi,

for me the problem with the final ContentProvider SQLite example – Events3 – seems repeatable.
When replacing Events2 with Events3 block by block (or when just copying Events3 into the workspace) 2 errors are in the Events class both with CONTENT_URI (marked with bold) saying ‘CONTENT_URI cannot be resolved’:

private void addEvent(String string) { 
 // Insert a new record into the Events data source. 
 // You would do something similar for delete and update. 
 ContentValues values = new ContentValues(); 
 values.put(TIME, System.currentTimeMillis()); 
 values.put(TITLE, string); 
 getContentResolver().insert(CONTENT_URI, values); 
 } 
private Cursor getEvents() { 
// Perform a managed query. The Activity will handle closing 
// and re-querying the cursor when needed. 
return managedQuery(CONTENT_URI, FROM, null, null, ORDER_BY); 
}

When I accept the ‘Create Constant CONTENT_URI’ autocorrection the code seems functional but on the Emulator I got ‘The application Events has stopped unexpectedly’ error.

03 Feb 2009, 12:28
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

In Constants.java you need to add:


import android.net.Uri;
...
   public static final String AUTHORITY = "org.example.events";
   public static final Uri CONTENT_URI = Uri.parse("content://" 
         + AUTHORITY + "/" + TABLE_NAME);

I just double-checked the .zip and the .tgz files to make sure you can find them in file code/Eventsv3/src/org/example/events/Constants.java . See also page 183 of the PDF or page 176 of the printed book, near the bottom of the page.

02 Feb 2009, 22:25
Generic-user-small

Attila Csordas (2 posts)

Those lines were already added to the code.
Actually this way:

public static final String AUTHORITY = "org.example.events"; 
public static final Uri CONTENT_URI = Uri.parse("content://" 
+ AUTHORITY + "/" + TABLE_NAME);
03 Feb 2009, 13:37
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

That looks correct so it should be working. If you zip up your project and email it to me at my gmail.com account (user ed.burnette) I’ll take a closer look. Meanwhile here are some things you can try:

- Verify you have relatively recent versions of everything, especially the Android SDK and emulator. Remove any old versions to make sure they’re not being run accidentally.
- Do a Project > Clean in Eclipse just to make sure everything is rebuilt correctly.
- Uninstall the application on the emulator (“adb uninstall org.example.events”) to rule out the possibility that your new code was not getting downloaded.
- Open the Android console (or run “adb logcat”) and run the program, capturing any tracebacks and errors you get.
- Run the program in debug mode and stop at the location of the error to see if you discover any clues to the problem. (You may need to set a breakpoint on the exception inside Eclipse.)

Hope this helps,
—Ed

  You must be logged in to comment