“在android.database.sqlite.SQLitepenhelper中没有可用的默认构造函数”在Android Studio中 [英] "There is no default constructor available in android.database.sqlite.SQLitepenhelper" in Android Studio

查看:1207
本文介绍了“在android.database.sqlite.SQLitepenhelper中没有可用的默认构造函数”在Android Studio中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用SQLiteOpenHelper扩展类,但是此错误显示:没有默认构造函数可用在android.database.sqlite.SQLitepenhelper以及其他无法解析符号类别,注意...

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 "cannot resolve symbol Category, Note,..."

class DbHelper extends SQLiteOpenHelper {


    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(Category.getSql());
        db.execSQL(Note.getSql());
        db.execSQL(Attachment.getSql());
        db.execSQL(CheckItem.getSql());
    }

    @Override
    public void onUpgrade(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);
    }


推荐答案

自己调用 super 构造函数SQLiteOpenHelper.html> SQLiteOpenHelper

You need to define an explicit constructor yourself that calls the 4- or 5-arg super constructor in SQLiteOpenHelper.

例如:

public DbHelper(Context context) {
    super(context, "database.db", null, 1);
}

其中 database.db 是您的数据库文件名, 1 是版本。

where database.db is your database file name and 1 is the version.

这篇关于“在android.database.sqlite.SQLitepenhelper中没有可用的默认构造函数”在Android Studio中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆