I’m a bit lost on this one. How can I get an OutOfBounds? Is there a size limit (besides sizeof (int))?
Maybe because multiple threads can come here? The UI thread and a Service thread?
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)
at
kenyu73.realsignal.BarScaleGraph$buildGraphThread.execute(BarScaleGraph.java:94)
at
kenyu73.realsignal.BarScaleGraph$buildGraphThread.run(BarScaleGraph.java:74)
Also, I’m calling this classes methods with a static instance. I’m thinking threads are competing for the same variables??? Thoughts?
BarScaleGraph class
ContentValues[] values = DatabaseWrapper.getInstance().getSignalValues(getContentResolver(), signal_type, false);
DatabaseWrapper class
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;
}
EDIT: Going to try this – add synchronized to the instance
// grab static instance so we only have one db wrapper
public static synchronized DatabaseWrapper getInstance() {
return instance;
}
I would guess this is a race condition, where the count is change between threads… try to synchronize the method:
If the previous does not fit you, there is always this:
This would solve the issue, but I would try to prevented this sort of methodology using different architecture.