[android-beginners] Re: Where's my ContentProvider
Faber Fedor wrote: I'm trying to build my first ContentProvider using the example in Mark's book A Busy Coder's Guide To Android Development (which I suggest other n00bs like me should read :-). Many thanks! My database is created; I can go in via the command line/SQLite interface and play with it. The database name is lbtdl.db and the only table in it is locations. However, when I do the following: locationsCursor = managedQuery(Provider.Locations.CONTENT_URI, FIELDS, null, null, null); ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.listlocations, locationsCursor, new String[] {Provider.Locations.NAME http://Provider.Locations.NAME}, new int[] {R.id.name http://R.id.name}); setListAdapter(adapter); selection= (TextView)findViewById(R.id.selection); locationsCursor is alway null, nothing is displayed, and logcat complains E/ActivityThread( 387): Failed to find provider info for com.appspot.lbtdl That suggests either your provider is not listed in your AndroidManifest.xml, or possibly it's not a public class. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.9 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Where's my ContentProvider
On Tue, Jan 6, 2009 at 8:43 PM, Mark Murphy mmur...@commonsware.com wrote: Faber Fedor wrote: locationsCursor is alway null, nothing is displayed, and logcat complains E/ActivityThread( 387): Failed to find provider info for com.appspot.lbtdl That suggests either your provider is not listed in your AndroidManifest.xml, I change my manifest (I keep forgetting that blasted thing!) to contain the class name and now things are working better. So the class name goes into the manifest. what is my CONTENT_URI then? I'm assuming it's content://com.appspot.lbtdl. Since I have a table called locations, I'll access all of the locations with content://com.appspot.lbtdl/locations, right? or possibly it's not a public class. That's just done in the declaration, of the class right? There's nothing else that needs to be done. -- Faber Fedor Cloud Computing New Jersey http://cloudcomputingnj.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Where's my ContentProvider
Faber Fedor wrote: So the class name goes into the manifest. what is my CONTENT_URI then? I'm assuming it's content://com.appspot.lbtdl. Since I have a table called locations, I'll access all of the locations with content://com.appspot.lbtdl/locations, right? You can. There's nothing forcing that pattern, though. What *is* magic is that there is a public static final Uri named CONTENT_URI, and that this Uri is the base Uri for your provider, and that it begins with content://. The use of a namespaced value as the first segment after the content:// prefix is a convention to prevent collisions, just as Java namespaces themselves tend to be based off of domain names, to prevent collisions. That's just done in the declaration, of the class right? There's nothing else that needs to be done. Correct. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.9 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Where's my ContentProvider
Faber Fedor wrote: What *is* magic is that there is a public static final Uri named CONTENT_URI, and that this Uri is the base Uri for your provider, and that it begins with content://. I must be missing something since that doesn't seem magical to me. Sorry. By magic I mean it has to be named CONTENT_URI and have the properties as listed. If you decided you didn't want to call it CONTENT_URI, it probably wouldn't work. I thought onCreate() was a constructor, i.e. whenever my app initialized and/or created an object, onCreate() would be called. Java has its own constructors. onCreate() is a callback used by some Android classes. It turns out the onCreate() is called if the datastore doesn't exist. There are lots of onCreate() callbacks. I'm assuming you're referring to the SQLiteOpenHelper, whose onCreate() documentation says: Called when the database is created for the first time. I say that because I kept dropping my table in SQLite but the ContentProvider.onCreate() was never called until I deleted the database from the hard drive. Correct. The more conventional approach, on schema changes, is to increment the version number of the database (fourth parameter to SQLiteOpenHelper constructor), which will trigger an onUpgrade() call to your SQLiteOpenHelper object. I assume all onCreates()s act similarly. For SQLiteOpenHelper implementations, yes. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 1.9 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---