クラスオブジェクトをdbに保存します。私はSerializableを使用しましたが、クラス内のオブジェクトの1つは常にnullです。オブジェクトをsqlite dbに保存
import com.google.android.gms.maps.model.LatLng;
import java.io.Serializable;
import java.util.ArrayList;
public class A implements Serializable {
protected String Name;
protected int Type;
protected transient List<LatLng> Nodes=new ArrayList<LatLng>();
}
ノード常にnullです。 「一時的」を削除すると、すべてのオブジェクトがnullになります。 DBに保存
は、このようなものです:
public long InsertList(A Data) {
byte[] bytes = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(Data);
oos.flush();
oos.close();
bos.close();
bytes = bos.toByteArray();
} catch (IOException ex) {
//TODO: Handle the exception
ex.printStackTrace();
;
}
ContentValues insertValues = new ContentValues();
insertValues.put("Data", bytes);
insertValues.put("Selected", 1);
return mDb.insert("Table", null, insertValues);
}
なぜRealmデータベースに移行しないのですか? –
@MohammedAtif私はsqliteに問題はありません。私の大きな問題はノードオブジェクトは常にnullです。 –
これを確認してください http://stackoverflow.com/questions/1243181/how-to-store-object-in-sqlite-database –