I am trying to develop a quiz app for physics, but I keep getting the error
02-23 16:02:06.006: E/Database(9348): on sqlite3_open_v2("data/data/com.mcq.srm/databases/q.db", &handle, 1, NULL) failed
Code Snippet below
public class QuestionPane extends Activity {
int counter =00;
RadioButton radioButton;
TextView Question;
TextView tvScore;
Button Next;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questionpane);
int resdb=0;
try {
SQLiteDatabase checkDB = null;
String DB_FULL_PATH = "data/data/com.mcq.srm/databases/q.db";
checkDB = SQLiteDatabase.openDatabase(DB_FULL_PATH, null,
SQLiteDatabase.OPEN_READONLY);
checkDB.close();
//Toast.makeText(this,"db "+checkDB, Toast.LENGTH_LONG).show();
resdb=0;
Log.v("msg","Database created");
} catch (Exception e){
resdb=1;
}
Log.v("msg", "check res-->"+resdb);
try{
db = openOrCreateDatabase("q.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null );
if(resdb==1)
{
Log.v("msg","creating tables");
CreateTable();
InsertData();
displayres();
}
}
catch(Exception e){
}
}
public void CreateTable(){
String Createtab;
Createtab =" CREATE TABLE tbl_Question ("+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, Questions TEXT, option_1 TEXT,option_2 TEXT, option_3 Text, option_4 TEXT, correct_answer TEXT);";
try{
db.execSQL(Createtab);
}
catch(Exception e){
}
}
public void InsertData(){
ContentValues values = new ContentValues();
values.put("question", "Two beams of red and violet colours are made to pass separately through a prism of A = 60°. In the minimum deviation position, the angle of refraction inside the prism will be");
//... value.put statements removed
db.insert("tbl_Question", null, values);
//.. values.put statements removed
values.put("correct_answer","35 grams");
db.insert("tbl_Question", null, values);
}
public void displayres() {
int qno=1;
String sql1="select * from question;";
Cursor c1=db.rawQuery(sql1,null);
Log.v("answer","asd");
String que,opt1,opt2,opt3,opt4;
startManagingCursor(c1);
c1.moveToFirst();
que=c1.getString(c1.getColumnIndex("Question1"));
Log.v("answer",que);
}
}
There are lot of mistakes in your I’ll suggest you go through this example, it’s best to start with that example in android.You need to create separate class for Database generally know as Database Adapter and one more that is Database Helper by Android Devs. So to get complete idea go through that example.