Why I can't clear a JGoDocument?

source is like this:
It’s always throw
java.lang.NullPointerException
at com.nwoods.jgo.JGoDocument.removeObjectAtPos(Unknown Source)
at swing.TestRemoveObjectFromDocument.testRemove(TestRemoveObje ctFromDocument.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)

import junit.framework.TestCase;

public class TestRemoveObjectFromDocument extends TestCase {
JGoDocument f=null;
protected void setUp() throws Exception {
super.setUp();
f=new JGoDocument();
f.addObjectAtTail(new JGoLink());
f.addObjectAtTail(new JGoLink());
f.addObjectAtTail(new JGoLink());
f.addObjectAtTail(new JGoLink());
f.addObjectAtTail(new JGoLink());
f.addObjectAtTail(new JGoLink());
}
public void testPosFetch(){
JGoListPosition pos=f.getFirstObjectPos();

}
public void testRemove(){
    JGoListPosition pos=f.getFirstObjectPos();
    int i=0;
    while(pos!=null){
        P.print(i);
        //pos=f.getNextObjectPos(pos);
        f.removeObjectAtPos(pos);
        //P.print((f.removeObjectAtPos(pos).toString()));
        i++;
        P.print(pos.toString());
        //pos=f.getNextObjectPos(pos);
        //assertNotNull(pos);
        //assertEquals(6,f.getNumObjects());
    }
    
}

}

I think the problem is that you are modifying the list while you are iterating over it. That’s not allowed.

In other words,I can’t clear the JGoDocument through this approach??

Well, first of all, it’s a bit unusual to even want to delete everything from a document programmatically.
If you want to delete all the objects and all but the first layer, you can just call JGoDocument.deleteContents.
If you just want to remove all the objects but leave all the layers, you can do:
public void removeAll(JGoDocument doc) {
JGoLayer layer = doc.getFirstLayer();
while (layer != null) {
layer.removeAll();
layer = layer.getNextLayer();
}
}
It’s odd that no one has ever asked about this, but I suppose we ought to provide this method on JGoDocument (without the argument, of course).

Thank you

Happy every day