I would like to share a fairly common error from Google Play Console (Android):
java.util.ConcurrentModificationException:
at java.util.HashMap$HashIterator.nextNode (HashMap.java:1442)
at java.util.HashMap$KeyIterator.next (HashMap.java:1466)
at com.shephertz.app42.gaming.multiplayer.client.WarpClient.onResponse (WarpClient.java:506)
at com.shephertz.app42.gaming.multiplayer.client.MessageDispatchThread.run (MessageDispatchThread.java:48)
What can this be related to?
I use App42MultiPlayerGamingSDK.jar (version 2.3).
Code:
public void quickGame() {
...
initAppWarp();
addListeners();
connectAppWarp();
}
private void initAppWarp() {
if (warpClient == null) {
try {
WarpClient.initialize(apiKey, secretKey);
warpClient = WarpClient.getInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void addListeners() {
if (warpClient != null) {
if (connectionListener == null) {
connectionListener = new ConnectionListener(this);
warpClient.addConnectionRequestListener(connectionListener);
}
if (roomListener == null) {
roomListener = new RoomListener(this);
warpClient.addRoomRequestListener(roomListener);
}
if (zoneListener == null) {
zoneListener = new ZoneListener(this);
warpClient.addZoneRequestListener(zoneListener);
}
if (notificationListener == null) {
notificationListener = new NotificationListener(this);
warpClient.addNotificationListener(notificationListener);
}
}
}
private void connectAppWarp() {
if (warpClient != null) {
warpClient.connectWithUserName(myId);
}
}
//-----------------------------------------
//-----------------------------------------
private void onConnectDone(boolean status) {
...
warpClient.joinRoomWithProperties(properties);
}
private void onJoinRoomDone(RoomEvent event) {
if (event.getResult() == WarpResponseResultCode.SUCCESS) {
...
warpClient.subscribeRoom(roomId);
} else if (event.getResult() == WarpResponseResultCode.RESOURCE_NOT_FOUND) {
...
warpClient.createRoom("game", "owner", 2, properties);
}
}
private void onRoomCreated(String roomId){
...
warpClient.joinRoom(roomId);
}
private void onRoomSubscribed(String roomId) {
...
warpClient.getLiveRoomInfo(roomId);
}
public void sendMessage(byte[] msgBuf) {
warpClient.sendPrivateUpdate(opponentId, msgBuf);
}
//-----------------------------------------
//-----------------------------------------
public void leaveGame() {
if (warpClient != null && state == ConnectedState.JOINED_ROOM) {
warpClient.unsubscribeRoom(roomId);
warpClient.leaveRoom(roomId);
if (roomId != null && roomId.length() > 0) {
warpClient.deleteRoom(roomId);
}
}
warpClient.disconnect();
}
@Override
public void onDisconnectDone(ConnectEvent event) {
removeListeners();
}
private void removeListeners() {
if (warpClient != null) {
warpClient.removeConnectionRequestListener(connectionListener);
warpClient.removeRoomRequestListener(roomListener);
warpClient.removeZoneRequestListener(zoneListener);
warpClient.removeNotificationListener(notificationListener);
connectionListener = null;
roomListener = null;
zoneListener = null;
notificationListener = null;
}
}