我对这个有点迷茫。如何获得 OutOfBounds?是否有大小限制(除了 sizeof (int))?
也许是因为多个线程可以来这里?UI线程和服务线程?
java.lang.ArrayIndexOutOfBoundsException at kenyu73.realsignal.DatabaseWrapper.getSignalValues(DatabaseWrapper.java:137) at kenyu73.realsignal.DatabaseWrapper.getSignalValues(DatabaseWrapper.java:116) at kenyu73.realsignal.BarScaleGraph$buildGraphThread.drawGraph(BarScaleGraph.java: 128) 在 kenyu73.realsignal.BarScaleGraph$buildGraphThread.execute(BarScaleGraph.java:94) 在 kenyu73.realsignal.BarScaleGraph$buildGraphThread.run(BarScaleGraph.java:74)
另外,我用静态实例调用这些类方法。我认为线程正在竞争相同的变量???想法?
条形图类
ContentValues[] values = DatabaseWrapper.getInstance().getSignalValues(getContentResolver(), signal_type, false);
数据库包装类
private static final DatabaseWrapper instance = new DatabaseWrapper();
// grab static instance so we only have one db wrapper
public static DatabaseWrapper getInstance() {
return instance;
}
. . . .
public ContentValues[] getSignalValues(ContentResolver cr, int signal_type_id, boolean bGroupByLatLon) {
String sWhere = "signal_type_id=" + signal_type_id;
Cursor cursor;
if (bGroupByLatLon) {
cursor = cr.query(CONSTS.CONTENT_URI_GRP_LATLNG, null, sWhere, null, null);
} else {
cursor = cr.query(CONSTS.CONTENT_URI_LOGGER, null, sWhere, null, null);
}
ContentValues[] values = new ContentValues[cursor.getCount()];
int count = 0;
if (cursor.getCount() > 0) {
cursor.moveToFirst();
do {
values[count] = new ContentValues(); // <--- LINE 137
values[count].put("signal_value", cursor.getInt(cursor.getColumnIndex("signal_value")));
values[count].put("latitude", cursor.getInt(cursor.getColumnIndex("latitude")));
values[count].put("longitude", cursor.getInt(cursor.getColumnIndex("longitude")));
values[count].put("timestamp", cursor.getLong(cursor.getColumnIndex("timestamp")));
values[count].put("network", cursor.getString(cursor.getColumnIndex("network")));
count++;
} while (cursor.moveToNext());
}
cursor.close();
return values;
}
编辑:要试试这个 - 添加同步到实例
// grab static instance so we only have one db wrapper
public static synchronized DatabaseWrapper getInstance() {
return instance;
}