View Full Version : [CLOSED] NPE when applying CheckStateListener on TreeViewer

10 May 2008, 3:48 PM
I moved my project from myGWT to extGWT.
I am using GWT 1.5 Milestone 2, gxt beta 2, java 1.5 and Netbeans 6.1 for development.

However, when using a CheckStateListener on my checkable TreeViewer I get a NullPointerException, this is a test snippet:

public void onModuleLoad() {

TreeModel model = new BaseTreeModel();
final TreeModel A = new BaseTreeModel();
TreeModel B = new BaseTreeModel();
TreeModel B1 = new BaseTreeModel();

A.set("name", "A");
B.set("name", "B");
B1.set("name", "B1");

Tree tree = new Tree();

final TreeViewer viewer = new TreeViewer(tree);
viewer.setLabelProvider(new ModelLabelProvider());
viewer.setContentProvider(new ModelTreeContentProvider());
// If adding the CheckStateListener, NPE appears
viewer.addCheckStateListener(new CheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent arg0) {
Window.alert("Checked state changed");


final Label label = new Label("This is a tree check test");
final Button button = new Button("Set 'A' checked");

button.addClickListener(new ClickListener(){
public void onClick(Widget w) {
viewer.setChecked(A, true);


My application worked fine before updating the framework, I remember this NPE was also fixed in an older version of myGWT - did I just miss sthg here?
Help is really appreciated!

Lukas P.

10 May 2008, 4:13 PM
I believe the viewer code/API is all being replaced in Beta3 with a new data model...so perhaps this will be a moot point? (though not sure)

Not really answering your problem, but something to consider ;)

11 May 2008, 12:22 AM
sounds good, but I would have to release my app in two weeks time (non-profit, but still my team will not be happy...) so I am quite suffering a setback now.

Would it be better to move back to mygwt or is there any work-around I could apply for now :-/

14 May 2008, 3:18 PM
As a workaround, you can listen for the CheckChange event on the tree itself. You can then get the TreeItem and call item.getData() to get your model object.

I am closing this bug as it is no longer valid.

19 May 2008, 6:15 PM
I'm having a similar issue, but the NPE results from the item not being set on the event object, so this workaround won't work for me. This is with using beta2.

[ERROR] Uncaught exception escaped
java.lang.NullPointerException: null
at com.extjs.gxt.ui.client.viewer.Viewer.getElementFromItem(Viewer.java:478)
at com.extjs.gxt.ui.client.viewer.TreeViewer.fireCheckStateChanged(TreeViewer.java:407)
at com.extjs.gxt.ui.client.viewer.TreeViewer.access$3(TreeViewer.java:402)
at com.extjs.gxt.ui.client.viewer.TreeViewer$2.handleEvent(TreeViewer.java:313)
at com.extjs.gxt.ui.client.viewer.TreeViewer$2.handleEvent(TreeViewer.java:1)
at com.extjs.gxt.ui.client.util.EventTable.sendEvent(EventTable.java:72)
at com.extjs.gxt.ui.client.util.Observable.fireEvent(Observable.java:94)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:434)
at com.extjs.gxt.ui.client.widget.tree.TreeItem.fireEvent(TreeItem.java:569)
at com.extjs.gxt.ui.client.widget.tree.TreeItemUI.onCheckChange(TreeItemUI.java:168)

19 May 2008, 6:29 PM
This seems to have fixed it..

diff /Users/deuce/dev/src/common/gxt-1.0-beta2/src/com/extjs/gxt/ui/client/widget/tree/TreeItem.java src/main/java/com/extjs/gxt/ui/client/widget/tree/TreeItem.java
> if (te.item == null) te.item = this;

22 May 2008, 5:12 AM
I'm having this same issue with beta3 and use the same TreeItem change to work around it...

22 May 2008, 6:16 AM
I think this is the same issue as discussed here (?) http://extjs.com/forum/showthread.php?t=36150

so fix is in SVN then...