Bugfix for Concurrent Exception

This commit is contained in:
Loch Christian (uib05376) 2020-11-10 21:31:58 +01:00
parent 9c1899fe42
commit 2b8017c475
3 changed files with 22 additions and 22 deletions

View File

@ -45,20 +45,14 @@ public class MainActivity extends AppCompatActivity implements Observer {
if (viewStackRef.getChildCount() > 0)
viewStackRef.removeViewAt(0);
viewStackRef.addView(newTrView);
//viewStackRef.addView(newTrView, 0);
//int childCount = viewStackRef.getChildCount();
//if (childCount > 30) {
// viewStackRef.removeViewAt(childCount-1);
//}
}
});
}
public void onStepButtonClick(View view) {
//for (int j = 0; j < 3000; j++) {
this.track.timeElapse();
//}
this.track.timeElapse();
}
public void onPlayButtonClick(View view) {

View File

@ -7,6 +7,7 @@ import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import java.util.ConcurrentModificationException;
import java.util.List;
public class TimeRecordView extends View {
@ -58,16 +59,21 @@ public class TimeRecordView extends View {
int y = 0;
List<List<VehicleTimeRecord>> stepList = this.track.getVtrList();
for (int curStepIdx = stepList.size()-1; curStepIdx >= stepList.size()-1-50 && curStepIdx >= 0; curStepIdx--) {
List<VehicleTimeRecord> step = stepList.get(curStepIdx);
int i = 0;
for (VehicleTimeRecord r : step) {
int left = (int) (this.pixelPerVehicle * r.getPosition());
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity()));
canvas.drawRect(left, y, left + this.pixelPerVehicle - 1,
y+10, this.paint);
i++;
try {
List<VehicleTimeRecord> step = stepList.get(curStepIdx);
int i = 0;
for (VehicleTimeRecord r : step) {
int left = (int) (this.pixelPerVehicle * r.getPosition());
this.paint.setColor(getColor(r.getVelocity(), r.getMaxVelocity()));
canvas.drawRect(left, y, left + this.pixelPerVehicle - 1,
y + 10, this.paint);
i++;
}
y += 10;
} catch (ConcurrentModificationException ex) {
System.out.println("Concurrent Exception occured, skipping record");
continue;
}
y += 10;
}
}
}

View File

@ -73,11 +73,11 @@ public class Track extends Observable {
this.setChanged();
this.notifyObservers();
this.clearChanged();
try {
Thread.sleep(125);
} catch (InterruptedException ex) {
}
// try {
// Thread.sleep(125);
// } catch (InterruptedException ex) {
//
// }
}
public float avg_step(int step){