private static final String DATABASE_NAME2 = "asd";
private static final String DATABASE_TABLE2 = "myreportstable";
private static final int DATABASE_VERSION2 = 1;
private DatabaseHelper ourdatabaseHelper;
private final Context ourdbContext;
private SQLiteDatabase ourReportsDatabase;
private static class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME2, null, DATABASE_VERSION2);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE2 + " (" + KEY_ROWID2
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME2
+ " TEXT NOT NULL, " + KEY_LOCATION2 + " TEXT NOT NULL, "
+ KEY_DISCREPTION2 + " TEXT NOT NULL, " +KEY_IMG2+" BLOB NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE2);
onCreate(db);
}
}
public ImplementsAppDB(Context c) {
ourdbContext = c;
}
public ImplementsAppDB open() throws SQLException {
ourdatabaseHelper = new DatabaseHelper(ourdbContext);
ourReportsDatabase = ourdatabaseHelper.getWritableDatabase();
return this;
}
public void close() {
ourdatabaseHelper.close();
}
public long CreateEntry(String name, String locationRP, String DiscreptionRP) {
// TODO Auto-generated method stub
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.home);
ByteArrayOutputStream out = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, out);
ContentValues cv = new ContentValues();
cv.put(KEY_NAME2, name);
cv.put(KEY_LOCATION2, locationRP);
cv.put(KEY_DISCREPTION2, DiscreptionRP);
cv.put(KEY_IMG2, out.toByteArray());
return ourReportsDatabase.insert(DATABASE_TABLE2, null, cv);
}
I want to store an image into a sqlite database. Name ,Location and Description passed from other class and image used of res.
im getting java.lang.NullPointerException when i try to insert image..
Please help.