我試圖每5秒更新一次jMapViewer上的標記。這似乎工作正常,直到你移動地圖。此時它會拋出java.util.ConcurrentModificationException
。移動jMapViewer java.util.ConcurrentModificationExceptionException
我認爲這是與嘗試同時訪問地圖標記列表的不同進程有關,但我不知道如何解決該問題。
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
loadUnits();
}
}, 5 * 1000, 5 * 1000);
private void loadUnits() {
String query = "SELECT callsign, currentlat,currentlon,previouslat,previouslon, mobile, uniticon FROM unit WHERE isdeleted=0;";
rs = DBase.runQuery(query);
kit.removeAllMapMarkers();
MapMarkerUnit x;
try {
while (rs.next()) {
x = new MapMarkerUnit(rs.getDouble("currentlat"),rs.getDouble("currentlon"));
if (rs.getInt("mobile") == 1) x.setMovement(true);
else x.setMovement(false);
x.setIconName(rs.getString("uniticon"));
x.setPriority(1);
kit.addMapMarker(x);
}
}
catch (SQLException e) {
System.out.print(e.toString());
}
}
感謝您的幫助。
基蘭
什麼是rs?你可以給MWE嗎? – 2014-09-02 14:43:52
RS是從MySQL數據庫中提取的ResultSet。對不起MWE?有點新的這一點。 – KieranS 2014-09-02 14:46:09
最小工作示例,換句話說,代碼可以編譯和實驗...... – 2014-09-02 14:46:22