java - How to fill the treeTableView correctly -


i have record in database being must in tree table view. here filling method:

 private void updategoods(){         goodspane.setcenter(goodtreetableview);         list<good> goodandfolderslist;        try {            goodandfolderslist = goodsservice.getgoods();//database query        }catch (sqlexception e){            goodandfolderslist = new arraylist<>();            log.log(level.error, e.getmessage());        }            list<good> goods = new arraylist<good>();//list roots            list<good> roots = new arraylist<good>();//list goods            (good : goodandfolderslist) {                if (good.isis_folder()) {                    roots.add(good);                } else {                    goods.add(good);                }            }            treeitem<good> rootitem = new treeitem<>();//the main root            (good root : roots) {                long folderid = root.getid();                treeitem<good> roottreeitem = new treeitem<>(root);                (good : goods) {//looking goods each folder                    if (good.getfolderid() == folderid) {                        treeitem<good> goodtreeitem = new treeitem<>(good);                        roottreeitem.getchildren().add(goodtreeitem);                    }                }                rootitem.getchildren().add(roottreeitem);//adding every folder main root            }                    goodtreetableview = new treetableview<>(rootitem);     } 

after method user doesn't see in treetableview. maybe there nessessary define cell content, code being put before goodtreetableview = new treetableview<>(rootitem); drops nullpointerexception:

        goodname.setcellvaluefactory((treetablecolumn.celldatafeatures<good, string> param) ->                 new readonlystringwrapper(param.getvalue().getvalue().getname()));         folderid.setcellvaluefactory((treetablecolumn.celldatafeatures<good, number> param) ->                 new readonlylongwrapper(param.getvalue().getvalue().getfolderid()));         is_folder.setcellvaluefactory((treetablecolumn.celldatafeatures<good, boolean> param) ->                 new readonlybooleanwrapper(param.getvalue().getvalue().isis_folder())); 

i guess reason of problem why drops npe can't figure out.

upd: if add setting cell value factory following stacktrace:

javafx.fxml.loadexception:  /d:/javaedi/linkserver/ediagent/target/classes/com/ediagent/edi/gui/main.fxml      @ javafx.fxml.fxmlloader.constructloadexception(fxmlloader.java:2595)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2565)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2435)     @ javafx.fxml.fxmlloader.load(fxmlloader.java:2403)     @ com.ediagent.edi.gui.main.initrootlayout(main.java:44)     @ com.ediagent.edi.gui.main.start(main.java:27)     @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$153(launcherimpl.java:821)     @ com.sun.javafx.application.launcherimpl$$lambda$51/1546859350.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$runandwait$166(platformimpl.java:323)     @ com.sun.javafx.application.platformimpl$$lambda$44/1712669532.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$null$164(platformimpl.java:292)     @ com.sun.javafx.application.platformimpl$$lambda$47/157858792.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.application.platformimpl.lambda$runlater$165(platformimpl.java:291)     @ com.sun.javafx.application.platformimpl$$lambda$46/1225373914.run(unknown source)     @ com.sun.glass.ui.invokelaterdispatcher$future.run(invokelaterdispatcher.java:95)     @ com.sun.glass.ui.win.winapplication._runloop(native method)     @ com.sun.glass.ui.win.winapplication.lambda$null$141(winapplication.java:102)     @ com.sun.glass.ui.win.winapplication$$lambda$37/152005629.run(unknown source)     @ java.lang.thread.run(thread.java:745) caused by: java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:483)     @ sun.reflect.misc.trampoline.invoke(methodutil.java:71)     @ sun.reflect.generatedmethodaccessor1.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:483)     @ sun.reflect.misc.methodutil.invoke(methodutil.java:275)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2560)     ... 18 more caused by: java.lang.nullpointerexception     @ com.ediagent.edi.gui.maincontroller.updategoods(maincontroller.java:309)     @ com.ediagent.edi.gui.maincontroller.initialize(maincontroller.java:328)     ... 28 more 

**upd:**rootitem: rootitem

you adding data gui element on fxml, re-initializing it. avoid re-initialization of fxml elements.

you can change signature of updategoods() :

public treeitem<good> updategoods() { ... } 

and use in maincontroller set items

goodtreetableview.setroot(updategoods()); 

preferably, can return data(list) updategoods() instead of returning treeitem. create in controller , set root of goodtreetableview.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -