2012-02-23 158 views
1

我試圖開發物理測驗應用測驗應用程序,但我不斷收到錯誤需要幫助開發Android

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 

代碼片段如下

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

嘗試提供一個短的,獨立的,正確的(可編譯),實施例。看看http://sscce.org/ – 2012-02-23 11:10:15

+0

爲什麼空行和數百萬個'values.put'?下次請修正拼寫錯誤,不要放置數百萬次的輸入,// TODO的空行和無用的代碼重複。讓人們有時間閱讀你的代碼和答案。是的,請閱讀常見問題。 – Siddharth 2013-02-05 07:21:09

+0

你是否檢查問題發佈的實際時間? – 2013-02-05 15:38:29

回答

1

有很多的錯誤在你的,我會建議你去通過this例子,這是最好的開始與android.You那個例子需要創建一個單獨的數據庫一般類所知道的數據庫適配器和一個更多的是由Android離散事件數據庫幫助。因此,通過這個例子來獲得完整的想法。

+0

謝謝你的確有幫助 – 2012-03-01 06:50:59