The Constructor Sqliteopenhelper() Is Undefined
Solution 1:
For class DbHelper extends SQLiteOpenHelper
you are doing this:
public DbHelper() {
super();
}
If you look in the Android docs for SQLiteOpenHelper, there is no SQLiteOpenHelper()
constructor so it is complaining.
Solution 2:
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
Look at he public ocnstrucors and pass right parms
SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)
Create a helper object to create, open, and/or manage a database.
SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler)
Create a helper object to create, open, and/or manage a database.
You need to use one of the above two constructors. But you have
public DbHelper() { // remove this
super();
}
You already have
publicDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
Edit:
You are creating a constructor of Activity
class which is wrong
publicclasswriteAlarmextendsActivity {
You have
publicwriteAlarm(Context c){
ourContext = c;
}
I would suggest you to move this
privatestaticclassDbHelperextendsSQLiteOpenHelper {
to separate .java file
Solution 3:
Too many things!!
Remove this:
public DbHelper() {
super();
}
And this:
publicwriteAlarm(Context c){
ourContext = c;
}
At onCreate put this:
ourContext = this;
In
@OverridepublicvoidonCreate(SQLiteDatabase db) {
You must create the database.
Solution 4:
I m showing one exmample For SqlLiteHelper
1)Creating class for sqlitehelper
public class SQLHelper extends SQLiteOpenHelper {
publicstaticfinalStringDB_NAME="myDatabase";
publicstaticfinalStringTBL_NAME="myTable";
publicstaticfinalStringCOL1="ID";
publicstaticfinalStringCOL2="Name";
publicstaticfinalStringCOL3="Mobile";
publicSQLHelper(Context context) {
super(context, DB_NAME, null, 1);
}
@OverridepublicvoidonCreate(SQLiteDatabase db) {
db.execSQL(createTable Query);
Log.d("tag", "Succesffull");
}
publicvoidInsertData(String val1,String val2) {
SQLiteDatabasedb= getWritableDatabase();
ContentValuescv=newContentValues();
cv.put(COL2, val1);
cv.put(COL3, val2);
db.insert(TBL_NAME, COL1, cv);
}
@OverridepublicvoidonUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}}
After Created your class after calling //initialize SQLHelper class
SQLHelper helper;
//Simply pass your current activity
helper = new SQLHelper(MainActivity.this);
Post a Comment for "The Constructor Sqliteopenhelper() Is Undefined"