PDA

View Full Version : [FIXED] NullPointerException in BorderLayout.onLayout



zaccret
15 Jun 2008, 11:39 PM
I have a BorderLayouted container. It has setLayoutOnChange(true) and is already rendered so when I want to add(west,westData) I get :

java.lang.NullPointerException: null
at com.extjs.gxt.ui.client.widget.layout.BorderLayout.onLayout(BorderLayout.java:108)
at com.extjs.gxt.ui.client.widget.Layout.layout(Layout.java:68)
at com.extjs.gxt.ui.client.widget.Container.doLayout(Container.java:252)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:343)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:235)
at com.extjs.gxt.ui.client.widget.Container.insert(Container.java:303)
at com.extjs.gxt.ui.client.widget.LayoutContainer.insert(LayoutContainer.java:214)
at com.extjs.gxt.ui.client.widget.LayoutContainer.add(LayoutContainer.java:121)The BorderLayout.onLayout() method tries to :

BorderLayoutData data = (BorderLayoutData) c.getData();
Map<String, Object> st = c.getState();
if (st.containsKey("collapsed")) {
switchPanels((ContentPanel) c);
} else if (st.containsKey("size") && (!(c instanceof CollapsePanel))) {
data.setSize((Float) st.get("size")); //line 108
}but if we look at LayoutContainer.insert(Widget,int,Object) :

public boolean insert(Widget widget, int index, Object layoutData) {
Component component = wrapWidget(widget);
boolean added = super.insert(component, index);
if (added && layoutData != null) {
component.setData(layoutData);
}
return added;
}we see that the data object is set AFTER the insert call so the data variable will be null in BorderLayout.onData(). I guess this could be easily fixed in LayoutContainer :

public boolean insert(Widget widget, int index, Object layoutData) {
Component component = wrapWidget(widget);
Object oldData = component.getData();
component.setData(layoutData);
boolean added = super.insert(component, index);
if (!added) {
component.setData(oldData);
}
return added;
}or something else.

darrellmeyer
16 Jun 2008, 8:54 AM
Fix is in SVN.