Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


Problem with adding nodes dynamically

  • Nikolay

    Hi everybody,

    I have the following task: I have a number of queries that I have to execute. After each query I have some result set, consisting of one array Result of Result objects. The Result object consists of an array of node labels. Each previous node has relation to the next.

    My task is to draw the new results in the graph after each query execution.

    The problem is that I have java.util.ConcurrentModificationException. I can't understand what causes this exception.

    The skeleton of my program is the following:
    init() - create a graph object, and make all adjustments on it (Colors, Layouts, Display…), and the first and the last node
    makeQuery() : Result

    My first and last nodes are the same each time. Only the nodes between them are different.

    Here is some code:

    Result[] result = null;
    for (int i = 0; i < queries.length; i++) {
         result = rlFinder.doExecuteQuery(queries[i]);
          if (result.length > 0) {
    public void drawResult(Result[] result) {
            Node prevNode = null;
            Node currentNode = null;
            Edge currentEdge = null;
            Edge prevEdge = null;
            String[] listURL = null;
            boolean[] isReversed = null;
            boolean isNode = false;
            int edgeIndex = 0;
            for (int i = 0; i < result.length; i++) {
                prevNode = firstObject;            
                currentNode = graph.addNode();  //Here I have the above mentioned exception!!!
                edgeIndex = 0;
                isNode = false;
                listURL = result[i].getListURL();//Get node labels
                isReversed = result[i].getIsReversed();//Tells me the direction of an edge between two nodes
                for (int j = 1; j < listURL.length-1; j++) {                
                    if (isNode) {
                        currentNode.setString(NAME_COLUMN, listURL[j]);
                        prevNode = currentNode;
                        if (j != listURL.length-2) {
                            currentNode = graph.addNode();
                        isNode = false;
                    } else {
                        if (!isReversed[edgeIndex++]) {   
                            prevEdge = graph.addEdge(prevNode, currentNode);                                        
                        } else {
                            prevEdge = graph.addEdge(currentNode, prevNode);                    
                        isNode = true;
                if (!isReversed[--edgeIndex]) {                    
                    currentEdge = graph.addEdge(prevNode, secondObject);
                } else {
                    currentEdge = graph.addEdge(secondObject, prevNode);
                graph.addEdge(prevNode, secondObject);

    I would be very thankful if you could help me.

    Kind Regards,