I want to write some data into SQLite database. In my application I have a main singleton class with code:
public class Singleton extends Application {
public static DBHelper dbHelper;
public static SQLiteDatabase db;
@Override
public void onCreate() {
super.onCreate();
dbHelper = new DBHelper(this);
db = dbHelper.getWritableDatabase();
}
}
DBHelper.java:
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "myDB", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE AlarmListTable ("
+ "id integer primary key autoincrement,"
+ "time text,"
+ "date text,"
+ "comment text,"
+ ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
I have an activity in which I have a method:
ContentValues cv = new ContentValues();
cv.put("time", entTime.getText().toString());
cv.put("date", entTime.getText().toString());
cv.put("comment", entTime.getText().toString());
Singleton.db.insert("AlarmListTable", null, cv);
But application crashes. Help me please. What is wrong with it?
Aucun commentaire:
Enregistrer un commentaire