ConcurrentModificationException

0 votes

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;
    }
}
asked Apr 5, 2020 in Android by Byril Games (25 points)
edited Apr 7, 2020 by Byril Games

1 Answer

0 votes
 
Best answer

I solved this problem! Technical support offered a solution.

I stopped removing listeners in the project. I removed the removeListeners() method from the code.

http://forum.shephertz.com/?qa=11075/concurrentmodificationexception-causing-app-crashes&show=11075#q11075

answered Apr 27, 2020 by Byril Games (25 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...