java - IllegalArgumentException: Unknown URL content:// CONTENT -
illegalargumentexception: unknown url content://
^ having nightmare above. i've checked variables , paths can't see issue is? appreciate pointers!
here's trace.
java.lang.illegalargumentexception: unknown url content://com.purewowstudio.topmovies.data.filmprovider/film_data @ android.content.contentresolver.insert(contentresolver.java:1203) @ com.purewowstudio.topmovies.data.databasehelper.addfilm(databasehelper.java:52) @ com.purewowstudio.topmovies.fragments.filmlist$getfilms.onpostexecute(filmlist.java:72) @ com.purewowstudio.topmovies.fragments.filmlist$getfilms.onpostexecute(filmlist.java:62) @ android.os.asynctask.finish(asynctask.java:632) @ android.os.asynctask.access$600(asynctask.java:177) @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:645) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5262) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:898) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:693)
content provider
public class filmprovider extends contentprovider { public static final string table_name = "film_data"; public static final string authority = "com.purewowstudio.topmovies.data.filmprovider"; public static final uri content_uri = uri.parse("content://" + authority + "/" + table_name); public static final int films = 1; public static final int films_id = 2; public static final urimatcher surimatcher = new urimatcher(urimatcher.no_match); static { surimatcher.adduri(authority, table_name, films); surimatcher.adduri(authority, table_name + "/#", films_id); } private databasehelper mdb; public boolean oncreate() { mdb = new databasehelper(getcontext(), null, null, 1); return false; } @override public string gettype(uri uri) { return null; } @override public cursor query(uri uri, string[] projection, string selection, string[] selectionargs, string sortorder) { sqlitequerybuilder querybuilder = new sqlitequerybuilder(); querybuilder.settables(moviedatacontract.table_name); int uritype = surimatcher.match(uri); switch (uritype) { case films_id: querybuilder.appendwhere(moviedatacontract.filmentry._id + "=" + uri.getlastpathsegment()); break; case films: break; default: throw new illegalargumentexception("unknown uri"); } cursor cursor = querybuilder.query(mdb.getreadabledatabase(), projection, selection, selectionargs, null, null, sortorder); cursor.setnotificationuri(getcontext().getcontentresolver(), uri); return cursor; } @override public uri insert(uri uri, contentvalues values) { int uritype = surimatcher.match(uri); sqlitedatabase sqldb = mdb.getwritabledatabase(); long id = 0; switch (uritype) { case films: id = sqldb.insert(moviedatacontract.table_name, null, values); break; default: throw new illegalargumentexception("unknown uri: " + uri); } getcontext().getcontentresolver().notifychange(uri, null); return uri.parse(moviedatacontract.table_name + "/" + id); }
databasehelper class
public class databasehelper extends sqliteopenhelper { private contentresolver mycr; public databasehelper(context context, string name, sqlitedatabase.cursorfactory factory, int version) { super(context, moviedatacontract.database_name, factory, moviedatacontract.database_version); mycr = context.getcontentresolver(); } @override public void oncreate(sqlitedatabase db) { db.execsql(moviedatacontract.filmentry.sql_create_table); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql(moviedatacontract.filmentry.delete_table); oncreate(db); } public void addfilm(film film){ sqlitedatabase db = this.getwritabledatabase(); contentvalues values = new contentvalues(); values.put(moviedatacontract.filmentry.column_film_title, film.gettitle()); values.put(moviedatacontract.filmentry.column_film_rating, film.getrating()); values.put(moviedatacontract.filmentry.column_film_runtime, film.getruntime()); values.put(moviedatacontract.filmentry.column_film_critics, film.getcritics()); values.put(moviedatacontract.filmentry.column_film_audience, film.getaudience()); values.put(moviedatacontract.filmentry.column_film_synopsis, film.getsynopsis()); values.put(moviedatacontract.filmentry.column_film_profile, film.getprofile()); mycr.insert(filmprovider.content_uri, values); db.insert(moviedatacontract.table_name, null, values); db.close(); }
manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.internet" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/topmoviestheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".detailfragment" android:label="@string/title_activity_detail_fragment" android:parentactivityname=".mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.purewowstudio.topmovies.mainactivity" /> <provider android:name=".data.filmprovider" android:authorities="com.purewowstudio.topmovies.data.filmprovider" android:exported="true"> </provider> </activity> </application> </manifest>
first, move <provider>
child of <application>
, not <activity>
.
second, change android:exported="true"
android:exported="false"
, until such time secure contentprovider
. stands, once fix <provider>
element location noted above, app can read , write in provider, unlikely user wants.
Comments
Post a Comment