1
votes

how to use the CollapsePath in Tree Component codename one

using Tree component using the collapsePath cause null pointer exception due to container = this .... how to solve this issue .. i am specified the arguments as string obj of parent, child, child can you specify the how to use collapsePath and expandPath i have tried using both the expandPath and collapsePath but both causing the same problem

Tree dt = new Tree(new StringArrayTreeModel()); dt.collapsePath("Colors","Red","df","gf");

1
What's the stack of the exception? Is the path expanded? - Shai Almog
Exception: java.lang.NullPointerException - null java.lang.NullPointerException at com.codename1.ui.tree.Tree.collapsePathNode(Tree.java:327) at com.codename1.ui.tree.Tree.collapsePath(Tree.java:377) at com.mycompany.myapp.MyApplication$6.actionPerformed(MyApplication.java:161 - Arun Raj
ya the tree has been expanded.. i hava tried to the expandPath but that throw the null pointer exception .......... - Arun Raj
Form hi = new Form("Welcome",BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE) Tree tree = new Tree(); tree.expandPath("Colors","Red"); hi.addComponent(BorderLayout.CENTER,tree); hi.show(); this too cause the null pointer exception - Arun Raj

1 Answers

0
votes

The correct thing for this case would be:

    Form current = new Form("Tree Test", new BorderLayout());
    Tree t = new Tree();

    current.add(BorderLayout.CENTER, t);
    current.addShowListener(e -> t.expandPath(null, "Colors"));
    current.show();

However, there is a bug in the current version related to the null root argument which should be fixed in the coming update next Friday (12th May 2017).