ビットマップを BLOB として格納し、いくつかの文字列を同じ SQLdatase に格納しようとしています。
ここに私のデータベースがあります:
// 単一の連絡先を更新
public int update(String name, String email, String uid, String tel, String niver, String created_at, byte[] thumb) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, name); // Name
values.put(KEY_EMAIL, email); // Email
values.put(KEY_UID, uid); // Email
values.put(KEY_TEL, tel); // Telefone
values.put(KEY_NIVER, niver); // Niver
values.put(KEY_CREATED_AT, created_at); // Created At
values.put(KEY_THUMB, thumb); // thumb
//db.close(); // I deleted this line
// updating row
return db.update(TABLE_LOGIN, values, KEY_THUMB + " = ?",
new String[] { String.valueOf(getRowCount()) });
}
これを使用して、ビットマップでデータベースを更新します。
imagebutton.setImageBitmap(photo);
imagebutton.setScaleType(ScaleType.FIT_XY);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
db.update(null, null, null, null, null, null, imageInByte);
ログ:
01-21 15:47:47.445: E/AndroidRuntime(24673): FATAL EXCEPTION: main
01-21 15:47:47.445: E/AndroidRuntime(24673): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65538, result=-1, data=Intent { act=inline-data (has extras) }} to activity {br.com.example.nightid/br.com.example.nightid.main.BaseSampleActivity}: java.lang.IllegalStateException: database not open
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.os.Looper.loop(Looper.java:130)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-21 15:47:47.445: E/AndroidRuntime(24673): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 15:47:47.445: E/AndroidRuntime(24673): at java.lang.reflect.Method.invoke(Method.java:507)
01-21 15:47:47.445: E/AndroidRuntime(24673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-21 15:47:47.445: E/AndroidRuntime(24673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-21 15:47:47.445: E/AndroidRuntime(24673): at dalvik.system.NativeStart.main(Native Method)
01-21 15:47:47.445: E/AndroidRuntime(24673): Caused by: java.lang.IllegalStateException: database not open
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1712)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1666)
01-21 15:47:47.445: E/AndroidRuntime(24673): at com.example.androidhive.library.DatabaseHandler.update(DatabaseHandler.java:150)
01-21 15:47:47.445: E/AndroidRuntime(24673): at br.com.example.nightid.slidingmenu.SlidingFragment.onActivityResult(SlidingFragment.java:204)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:161)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.app.Activity.dispatchActivityResult(Activity.java:3919)
01-21 15:47:47.445: E/AndroidRuntime(24673): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
01-21 15:47:47.445: E/AndroidRuntime(24673): ... 11 more