为什么我的内容会得到错误?

时间:2011-05-12 04:19:19

标签: java android uri android-contentprovider

这是一个扩展basecolumns的类

public static final String AUTHORITY = "imammuda";
public static final String PROGRAMPATH = "Program";

public static final Uri PROGRAM_URI = Uri.parse("content://" + AUTHORITY + "/" + PROGRAMPATH);

这是扩展contentprovider

的contentProvider类
static{
    sUriMatcher.addURI(ImamShareData.AUTHORITY, ImamShareData.PROGRAMPATH, PROGRAM);
    sUriMatcher.addURI(ImamShareData.AUTHORITY, ImamShareData.PROGRAMPATH + "/#", PROGRAM_ID);
}
@Override
public Uri insert(Uri uri, ContentValues initialvalues) {
    TableNumber = sUriMatcher.match(uri);
    if( TableNumber != PROGRAM){
        throw new IllegalArgumentException("Unknown URI " + uri);
    }
}

这是一个扩展expandablelist活动的类

private void createdata(){
(...)
(...)
    for(int i = 0; i < title.length; i++){
        ContentValues values = new ContentValues();
        values.put(ImamShareData.DataContent.KEY_PROGRAM_TITLE, title[i]);
        Uri group = cr.insert(ImamShareData.DataContent.PROGRAM_URI, values); <== when call give error
    }

这是清单xml

<provider android:authorities="imammuda" android:name="contentProvider" android:multiprocess="true"></provider>

这是logcat

05-12 12:03:49.823: ERROR/AndroidRuntime(3875): Caused by: java.lang.IllegalArgumentException: Unknown URI content://imammuda/Program
05-12 12:03:49.823: ERROR/AndroidRuntime(3875):     at com.android.imammuda.contentProvider.insert(contentProvider.java:139)
05-12 12:03:49.823: ERROR/AndroidRuntime(3875):     at android.content.ContentProvider$Transport.insert(ContentProvider.java:197)
05-12 12:03:49.823: ERROR/AndroidRuntime(3875):     at android.content.ContentResolver.insert(ContentResolver.java:592)
05-12 12:03:49.823: ERROR/AndroidRuntime(3875):     at com.android.imammuda.Program.createdata(Program.java:53)
05-12 12:03:49.823: ERROR/AndroidRuntime(3875):     at com.android.imammuda.Program.onCreate(Program.java:32)

1 个答案:

答案 0 :(得分:1)

在AndroidManifest文件中,提到android:name元素下的完整包名称。 尝试使用权限作为包名。