【发布时间】:2011-05-01 20:13:54
【问题描述】:
首先,我以前从未使用过数据库。在阅读了多篇文章后,将我的程序收集的数据存储在 SQLite 数据库中听起来是个好主意。目前,我的问题涉及存储 GeoPoints 的 ArrayList。我知道这不能存储在 sqlite 数据库中。我已经阅读了其他一些类似的问题,发现解决方案可能是创建一个单独的表,并将所有点存储在该表的两列中。
在我的数据库适配器中,我写道:
// Make a New GeoPoint Table
public void geopointTable(String routeName)
{
String GeoTable = "CREATE TABLE " + routeName + "geopoints (_id INTEGER PRIMARY KEY, "
+ "KEY_GEOLONG REAL, "
+ "KEY_GEOLAT REAL);";
db.execSQL(GeoTable);
}
// Insert into GeoPoint Table
public long insertGeopoints (double longitude, double latitude, String routeName)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_GEOLONG, longitude);
initialValues.put(KEY_GEOLAT, latitude);
return db.insert(routeName + "geopoints", null, initialValues);
}
在我收集地理点并将它们存储在数组中的主要活动中,我写道:
db.open();
db.geopointTable(routeName);
Iterator<GeoPoint> i = points.iterator();
while (i.hasNext()) {
db.insertGeopoints(i.next().getLongitudeE6(), i.next()
.getLatitudeE6(), routeName);
这会导致致命异常。我想,最后,我想在我的行中有一个列来承载承载地理点的表的名称。有谁知道更简单的方法,或者可以看到代码的问题。
【问题讨论】: