问题
I get this error everytime I try to use my content provider to insert a URI. Here is the method:
private void sample() {
ContentValues values;
values = new ContentValues();
values.put(Formulas.TITLE, "Formula1");
values.put(Formulas.FORMULA, "someformula");
getContentResolver().insert(getIntent().getData(), values);
values = new ContentValues();
values.put(Formulas.TITLE, "Formula2");
values.put(Formulas.FORMULA, "someformula");
getContentResolver().insert(getIntent().getData(), values);
values = new ContentValues();
values.put(Formulas.TITLE, "Formula3");
values.put(Formulas.FORMULA, "someformula");
getContentResolver().insert(getIntent().getData(), values);
}
Previously I set the Intent data here:
Intent intent = getIntent();
if (intent.getData() == null)
intent.setData(Formulas.CONTENT_URI);
Here is my content URI and authority:
public static final String AUTHORITY = "com.mohit.provider.FormulaProvider";
public static final Uri CONTENT_URI = Uri.parse("content:\\" + AUTHORITY + "\formulas");
Here is the provider tag:
<provider android:name="com.mohit.provider.FormulaProvider"
android:authorities="com.mohit.provider.FormulaProvider" />
And finally the Logcat log:
08-22 14:42:07.362: ERROR/AndroidRuntime(338): FATAL EXCEPTION: main
08-22 14:42:07.362: ERROR/AndroidRuntime(338): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mohit.gformula.activities/com.mohit.gformula.activities.FormulasList}: java.lang.IllegalArgumentException: Unknown URL content:\\com.mohit.provider.FormulaProvider\formulas
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.os.Looper.loop(Looper.java:123)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at java.lang.reflect.Method.invoke(Method.java:521)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at dalvik.system.NativeStart.main(Native Method)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): Caused by: java.lang.IllegalArgumentException: Unknown URL content:\\com.mohit.provider.FormulaProvider\formulas
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.content.ContentResolver.insert(ContentResolver.java:583)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at com.mohit.gformula.activities.FormulasList.sample(FormulasList.java:38)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at com.mohit.gformula.activities.FormulasList.onCreate(FormulasList.java:23)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-22 14:42:07.362: ERROR/AndroidRuntime(338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
What could be the problem?
回答1:
backslashes \ look strange in a URI, try // resp. /
来源:https://stackoverflow.com/questions/3541894/unknown-url-contentunknown-url-content-com-mohit-provider-formulaprovider-form