How to troubleshoot NPE during UIBinder component initialization

34 views
Skip to first unread message

grigory

unread,
Mar 23, 2011, 10:21:39 AM3/23/11
to Google Web Toolkit
Having the NPE problem during view initialization I determined that
this element

@UiField(provided=true)
ShortMessageBox shortMessageBox;

causes it. When I remove it from the view everything works fine.

The ShortMessageBox is defined UIBinder-based componet:

public class ShortMessageBox extends Composite {

public interface ShortMessageBoxUiBinder extends UiBinder<Widget,
ShortMessageBox> {
}

@Inject
public ShortMessageBox(final ShortMessageBoxUiBinder
uiBinder) {
super();

initWidget(uiBinder.createAndBindUi(this));
clearMessageWidget();
}
....
}

As you can see I am using gin but I have other similarly defined
components that work just fine. Since I am not looking for solution
with this question I don't provide all supporting code.

The question is how to troubleshoot/debug UIBinder views and
components when the following exception encountered during
initialization:

Caused by: java.lang.NullPointerException
at
com.myapp.client.ui.ShortMessageBox_ShortMessageBoxUiBinderImpl.createAndBindUi(ShortMessageBox_ShortMessageBoxUiBinderImpl.java:
18)
at
com.myapp.client.ui.ShortMessageBox_ShortMessageBoxUiBinderImpl.createAndBindUi(ShortMessageBox_ShortMessageBoxUiBinderImpl.java:
1)
at com.myapp.client.ui.ShortMessageBox.<init>(ShortMessageBox.java:
33)
at com.myapp.client.gin.MyAppGinjectorImpl.com$myapp$client$ui
$ShortMessageBox_ShortMessageBox_methodInjection(MyAppGinjectorImpl.java:
1058)


My problem is that something obviously going wrong during
ShortMessageBox initialization but no detailed information or ways to
debug it that I know of...

Y2i

unread,
Mar 23, 2011, 10:59:21 AM3/23/11
to google-we...@googlegroups.com, grigory
More likely you are calling createAndBindUi() before initializing shortMessageBox

Thomas Broyer

unread,
Mar 23, 2011, 12:35:47 PM3/23/11
to google-we...@googlegroups.com, grigory
To debug generated code: pass the -gen argument to DevMode (e.g. -gen gen) so you can look at the generated code (will be emitted to the given folder). Here, you could then have access to the generated createAndBindUi method and the line 18 where the error occurs.
You can also add the folder to the Sources tab in your Eclipse launcher (assuming you're using Eclipse) and Eclipse will now allow you to step into the generated class.

grigory

unread,
Mar 24, 2011, 8:15:48 AM3/24/11
to Google Web Toolkit
No.

private static MainPageViewUiBinder uiBinder =
GWT.create(MainPageViewUiBinder.class);

@Inject
public MainPageView(SignInOutLink signInOutLink, ShortMessageBox
shortMessageBox) {
this.signInOutLink = signInOutLink;
this.shortMessageBox = shortMessageBox;

widget = uiBinder.createAndBindUi(this);
Message has been deleted

grigory

unread,
Mar 25, 2011, 9:54:06 AM3/25/11
to Google Web Toolkit
Thanks,
adding "-gen <folder>" compiler argument (and adding the <folder> to
classpath when running in dev.mode) helped with both generated code
and more informative error messages. I was missing inherited modules
in the application gwt.xml file.
Reply all
Reply to author
Forward
0 new messages