2012-09-09 33 views
0

我已經編寫了代碼以將圖像存儲在sqlitedatabase中,並且還編寫了獲取所有記錄的方法,但在獲取數據時,我將Exception作爲Nullpointer Exception.I在selectall中做了任何錯誤方法 ?從SqliteDatabase中重新獲取數據的異常

public class DBUserAdapter { 

    private static final String DATABASE_NAME = "users"; 
    private static final int DATABASE_VERSION = 1; 

    private static final String USERDETAILS= 
      "create table userdetails(usersno integer primary key autoincrement,photo BLOB,date text not null);"; 

    private Context context = null; 
    private DatabaseHelper DBHelper; 
    private SQLiteDatabase db; 
    public DBUserAdapter(Context context) { 
     this.context = context; 
     DBHelper = new DatabaseHelper(context); 

    } 
    private static class DatabaseHelper extends SQLiteOpenHelper 
    { 
     DatabaseHelper(Context context) 
     { 
      super(context, DATABASE_NAME, null, DATABASE_VERSION); 
     } 

     public void onCreate(SQLiteDatabase db) { 
      db.execSQL(USERDETAILS); 

     } 

     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
      // TODO Auto-generated method stub 
      db.execSQL("DROP TABLE IF EXISTS users"); 
      onCreate(db); 
     } 
    } 


    public void open() throws SQLException 
    { 
     db = DBHelper.getWritableDatabase(); 
     return; 
    } 

    public void close() 
    { 
     DBHelper.close(); 
    }  


    public long insert(byte[] photo, String date) 
    { 


     ContentValues initialValues = new ContentValues(); 
     initialValues.put("photo", photo); 
     initialValues.put("date", date); 
     // initialValues.put(KEY_TIME, time); 
     Log.d("inotvaluessssssssss",initialValues.toString()); 
     Log.d("dbbbbbbbbbb++++++*******", db.toString()); 
     return db.insert("userdetails", null, initialValues); 

    } 

    public Cursor selectAll(String TABLE_NAME, String COLUMNS, String SELECTION, String[] SELECTION_ARGS, 
      String GROUP_BY, String HAVING, String OREDER_BY) { 
     // TODO Auto-generated method stub 
     Cursor cursor = this.db.query(TABLE_NAME, new String[] { COLUMNS }, 
       SELECTION, SELECTION_ARGS, GROUP_BY, HAVING, OREDER_BY); 
     return cursor; 

    } 


} 
+0

請具體談談例外。粘貼在日誌中。 – kdehairy

回答

0

創建一個ArrayList,它將保存從數據庫收集的所有數據。

ArrayList<ArrayList<Object>> dataArrays = new ArrayList<ArrayList<Object>>(); 

這是一個創建「遊標」對象的數據庫調用。 遊標對象存儲從數據庫收集的信息並用於遍歷數據。

複合劑代碼在這裏...

​​
相關問題