onCreate()
方法 inContentProvider
没有被调用。虽然当我单击一个按钮时,它会进入insert()
方法并返回java.lang.NullPointerException
. 在onCreate()
方法中我只有
@Override
public boolean onCreate() {
Log.v(TAG,"Inside create provider");
database = new DatabaseSQLiteMyDB(getContext());
return false;
}
日志 CAT 显示:
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
在清单中:
<provider android:name="somepkg.CustomContentProvider"
android:authorities="somepkg.provider" />
在单击创建 URI 时:
{
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();
}