For loop not working

I call the addNotify () method in the class that I posted here. The problem is that when calling addNotify (), as in the code, setKeys (objs) does nothing. Nothing is displayed in my application explorer.

But when I call addNotify () without a loop (for int ....) and add only one element to the ArrayList, it shows that one element is correct.

Does anyone know where there might be a problem? See Cede

class ProjectsNode extends Children.Keys{
private ArrayList objs = new ArrayList();

public ProjectsNode() {


}

    @Override
protected Node[] createNodes(Object o) {
    MainProject obj = (MainProject) o;
    AbstractNode result = new AbstractNode (new DiagramsNode(), Lookups.singleton(obj));
    result.setDisplayName (obj.getName());
    return new Node[] { result };
}

@Override
protected void addNotify() {
    //this loop causes nothing appears in my explorer.
    //but when I replace this loop by single line "objs.add(new MainProject("project1000"));", it shows that one item in explorer
    for (int i=0;i==10;i++){
        objs.add(new MainProject("project1000"));
    }
    setKeys (objs);
}

}

+3
source share
2 answers

Take a look at this loop:

for (int i=0;i==10;i++)

This will start with i = 0 and continue moving until i = 10. I think you mean:

for (int i = 0; i < 10; i++)

(Added extra spaces for clarity.)

+5
source

John is right ... your loop is likely to be wrong.

for-loop while, ...

... ( while-loop-ness)

int i = 0;

while (i==10) {
    objs.add(new MainProject("project1000"));
    i++;
}
setKeys (objs);

addNotify , add ...

+1

Source: https://habr.com/ru/post/1738055/


All Articles