I am new to using gwt, although I am starting to get the hang of things. One perplexing situation I came across today was the following. (This is abbreviated to simplify my question)
public class MyPanel extends DecoratorPanel{
public MyPanel(){
final TextBox tb = new TextBox();
tb .setText("test");
this.add(tb);
tb .setFocus(true);
}
}
public class ClassA implements EntryPoint(){
public void onModuleLoad(){
MyPanel mp = new MyPanel();
RootPanel.get("reference").add(mp);
}
}
for some reason my problem occurs at the line:
RootPanel.get("reference").add(log);
I get a null pointer exception...the lines of the stack above the line that points at the line above is:
java.lang.NullPointerException: null
at com.google.gwt.user.client.ui.Panel.doAttachChildren(Panel.java:163)
at com.google.gwt.user.client.ui.Widget.onAttach(Widget.java:259)
at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:393)
at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:119)
at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:86)
at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:80)
So I thought this would just be a simple problem however, when I put all the code from MyPanel into ClassA in the onModuleLoad method and just created a DecoratorPanel in there, there was no null pointer exception. Why is this, and how can I fix it. It seems like a simple problem but I am not sure which direction to go. Anyone have an idea?
The null pointer exception happens on this line in Panel:
for (Iterator it = iterator(); it.hasNext();) {