I tried to save an object into sqlite, and the class of the object has implemented Serializable. But there is always an error:
android.database.sqlite.SQLiteException: unrecognized token:
"[Ljava.lang.Object;@277c81d9" (code 1): , while compiling: insert
into mClass(classData) values(?)[Ljava.lang.Object;@277c81d9
Here is my code:
public boolean add(ReturnInfo ri) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
db = dh.getWritableDatabase();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(ri);
oos.flush();
byte[] data = bos.toByteArray();
bos.close();
oos.close();
db.execSQL("insert into mClass(classData) values(?)" + new Object[]{data});
db.close();
Log.e("db", "insert succeeded");
return true;
} catch (Exception e) {
e.printStackTrace();
Log.e("db", "insert failed");
return false;
}
The database has been created successfully, I have no idea where went wrong.