每当我尝试使用内容提供程序插入URI时,我都会收到此错误。这是方法:
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);
}
以前我在这里设置了Intent数据:
Intent intent = getIntent();
if (intent.getData() == null)
intent.setData(Formulas.CONTENT_URI);
这是我的内容URI和权限:
public static final String AUTHORITY = "com.mohit.provider.FormulaProvider";
public static final Uri CONTENT_URI = Uri.parse("content:\\" + AUTHORITY + "\formulas");
这是提供者标签:
<provider android:name="com.mohit.provider.FormulaProvider"
android:authorities="com.mohit.provider.FormulaProvider" />
最后是Logcat日志:
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)
可能是什么问题?
答案 0 :(得分:5)
反斜杠\在URI中看起来很奇怪,试试// resp。 /