단일 테이블 'user_authentication'을 사용하여 sqlite3에 데이터베이스를 만드는 사용자 정의 contentprovider를 작성했습니다.android custom contentprovider
db 및 테이블은 해당 onCreate()
메서드에서 만들어졌지만 오버라이드 된 삽입 메서드에서는 NullPointerException
이 표시됩니다. 아래의 방법 :
public Uri insert(Uri uri, ContentValues initialvalues){
SQLiteDatabase sqlitedb = dbHelper.getWritableDatabase();
if(sUriMatcher.match(uri)!= TABLE){
throw new IllegalArgumentException("Unkown Uri"+uri);
}
ContentValues values;
if(initialvalues != null){
values = new ContentValues(initialvalues);
}
else{
values = new ContentValues();
}
long rowId = sqlitedb.insert(AUTHENTICATION_TABLE_NAME, "", values);
if(rowId>0){
Uri uril = ContentUris.withAppendedId(User.CONTENT_URI, rowId);
getContext().getContentResolver().notifyChange(User.CONTENT_URI, null);
sqlitedb.close();
return uril;
}
throw new SQLException("Failed to insert row into User_Authentication : " + uri);
}
디버깅하는 동안, I는 해당 테이블은 (는) getContext()
도달 할 때 널 그래서 에러 돌아가지만 '값'이 삽입되는 참조.
사용자 지정 contentprovider 클래스가 android.content.ContentProvider
을 확장하기 때문에 getContext()
이 null을 반환하는 이유가 궁금합니다.
아무도 도와 주실 수 없습니까? BTW, 내가는 getContext 대신 작동합니다
감사합니다, 라자 찬드라 Rangineni
onCreate()가 호출 된 후 호출됩니까? – MByD