"there Is No Default Constructor Available In Android.database.sqlite.sqlitepenhelper" In Android Studio
Trying to extend class with SQLiteOpenHelper, but this error shows up : 'There is no default constructor available in android.database.sqlite.SQLitepenhelper' along with other 'can
Solution 1:
You need to define an explicit constructor yourself that calls the 4- or 5-arg super
constructor in SQLiteOpenHelper
.
For example:
publicDbHelper(Context context) {
super(context, "database.db", null, 1);
}
where database.db
is your database file name and 1
is the version.
Solution 2:
If your DBHelper
child then this post help, othervise you can allready understandfirst Define it like this one in outside of you class, means uperside...
private DBHelper ourHelper;
privatefinal Context ourContext;
Then use this
classDbHelperextendsSQLiteOpenHelper {
publicDBHelper(Context context) {
super(context, DB_NAME, null, DB_VIRSION);
// TODO Auto-generated constructor stub
}
@OverridepublicvoidonCreate(SQLiteDatabase db) {
db.execSQL(Category.getSql());
db.execSQL(Note.getSql());
db.execSQL(Attachment.getSql());
db.execSQL(CheckItem.getSql());
}
@OverridepublicvoidonUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + Category.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + Note.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + Attachment.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + CheckItem.TABLE_NAME);
onCreate(db);
}
And then try this context for your parent class
publicMyDatabase(Context c){
ourContext=c;
}
Post a Comment for ""there Is No Default Constructor Available In Android.database.sqlite.sqlitepenhelper" In Android Studio"