I have been trying to solve what seems like a simple problem for the last 3 days, I am trying to insert a record into an sqlite database from an activity, I have searched for the issue without look. Below you find my activity code and DBHelper code. dbhelper CODE:
public Long insertResult(String QUEST_ID,String test1,String test2) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues initialValues = new ContentValues();
initialValues.put("Question", QUEST_ID);
initialValues.put("Rights", test1);
initialValues.put("Wrongs", test2);
Log.d("Result:", "Rights " + initialValues.get("Rights"));
return db.insertOrThrow("Results", null, initialValues);
}
from the mainactivity
long ins = myDbHelper.insertResult("test","test2","test3");
Results table doesn't exist in the database.
It looks like your DBHelper
is extending SQLiteOpenHelper
. You should override the onCreate
method in DBHelper
. For example, add something like this:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table Results (_id integer primary key autoincrement, Question text not null, Rights text not null, Wrongs text not null);");
}
If you ever change your database schema you'll also need to override the onUpgrade
method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.