android - onCreate() in ContentProvider is not being called -
oncreate()
method in contentprovider
not being called. though when click on button, goes inside insert()
method , returns java.lang.nullpointerexception
. in oncreate()
method have have
@override public boolean oncreate() { log.v(tag,"inside create provider"); database = new databasesqlitemydb(getcontext()); return false; }
log cat shows:
04-20 01:23:00.543: v/clicked(1607): clicked 04-20 01:23:00.553: v/provider(1607): inside insert 04-20 01:23:00.573: v/database(1607): created 04-20 01:23:00.573: e/pkg.onput_clicklistener(1607): java.lang.nullpointerexception 04-20 01:23:00.583: v/pkg.onput_clicklistener(1607): in exception code
in manifest :
<provider android:name="somepkg.customcontentprovider" android:authorities="somepkg.provider" />
while creating uri upon click :
{ myuri=builduri("content", "somepkg.provider"); this.putno=putno; mcontentvalues = inittestvalues(); } private uri builduri(string scheme, string authority) { uri.builder uribuilder = new uri.builder(); uribuilder.authority(authority); uribuilder.scheme(scheme); return uribuilder.build(); }
you need show code perform insert.
sorry rest of not targeted directly @ question, i've seen on place in code samples contentproviders.
you should not call database = new databasesqlitemydb(getcontext());
in contentprovider oncreate. reason given in sqliteopenhelper documentation getreadabledatabase , getwritabledatabase:
like getwritabledatabase, method may take long time return, should not call application main thread, including contentprovider.oncreate().
instead hold reference sqliteopenhelper instance , call getwritabledatabase/getreadabledatabase appropriate in query/insert/delete/update methods called asynchronously if using loaders.
Comments
Post a Comment