2014-12-27 17 views
7

SQLiteOpenHelper ile sınıfı genişletmeye çalışıyorum, ancak bu hata ortaya çıkıyor: "android.database.sqlite.SQLitepenhelper içinde kullanılabilir varsayılan kurucu yok "diğeri ile birlikte 'Not, sembol Kategori çözemezse ...'"Android.database.sqlite.SQLitepenhelper'da varsayılan bir kurucu yoktur" Android Studio'da

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); 
    } 

cevap

13

Sen SQLiteOpenHelper içinde 4- veya 5-arg super yapıcısını çağırır açık bir yapıcı kendiniz tanımlamak gerekir. Örneğin

:

public DbHelper(Context context) { 
    super(context, "database.db", null, 1); 
} 
database.db veritabanı dosya adıdır

ve 1 versiyonudur.

+0

WebView sınıfı, ancak bu yine de sorumu yanıtladı. Teşekkürler! – Seth

2

sizin DBHelper çocuk daha sonra bu yayını yardım, allready understandfirst size sınıfının dışında bu gibi bunu tanımla edebilirsiniz Othervise uperside anlamına geliyorsa ...

private DBHelper ourHelper; 
private final Context ourContext; 

O zaman bu

class DbHelper extends SQLiteOpenHelper { 
public DBHelper(Context context) { 
     super(context, DB_NAME, null, DB_VIRSION); 
     // TODO Auto-generated constructor stub 
    } 

@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); 
} 
kullanmak

Ve daha sonra bu bağlamı ana sınıfınız için deneyin.

public MyDatabase(Context c){ 
    ourContext=c; 
} 
İlgili konular