我已经编写了将图像存储在 sqlitedatabase 中的代码,还编写了获取所有记录的方法,但是在获取数据时,我得到了异常为 Nullpointer 异常。我在 selectall 方法中做错了什么?
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;
}
}