NullPointerException when adding a custom control

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

NullPointerException when adding a custom control

Postby Paul.Helster » Mon Apr 18, 2005 5:50 am

I get a NullPointerException when adding a custom control. Here is how to reproduce it on Eclipse 3.0.1, and SWT-Designer Trial 4.0.0.

1- Using the designer, I created the custom composite that I included in this message.

2- I managed to have this composite to be offered as a Custom Control.

3- I created a new SWT Composite in the designer.

4- I tried to put the composite from #1 into the new composite. Nothing gets added and the log shows this:

Code: Select all
java.lang.NullPointerException
   at com.swtdesigner.model.swt.forms.control.FormsLabelInfo.createSingleControl(FormsLabelInfo.java:70)
   at com.swtdesigner.model.swt.widgets.control.ControlInfo.createControl(ControlInfo.java:390)
   at com.swtdesigner.model.swt.widgets.composite.AbstractCompositeInfo.createControl(AbstractCompositeInfo.java:152)
   at com.swtdesigner.model.swt.widgets.composite.ThisCompositeInfo.createControl(ThisCompositeInfo.java:99)
   at com.swtdesigner.model.swt.widgets.composite.FrameInfo.createControl(FrameInfo.java:512)
   at com.swtdesigner.model.swt.widgets.composite.AbstractCompositeInfo.createControl(AbstractCompositeInfo.java:152)
   at com.swtdesigner.model.swt.widgets.composite.ThisCompositeInfo.createControl(ThisCompositeInfo.java:99)
   at com.swtdesigner.model.swt.widgets.composite.AbstractCompositeInfo.createControl(AbstractCompositeInfo.java:137)
   at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5469)
   at com.swtdesigner.model.swt.widgets.control.ControlInfo.notifyPropertyChanged(ControlInfo.java:206)
   at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5456)
   at com.swtdesigner.model.JavaInfo.unlockNotify(JavaInfo.java:5429)
   at com.swtdesigner.model.JavaInfo.endEdit(JavaInfo.java:831)
   at com.swtdesigner.gef.command.swt.layout.absolute.AbsoluteAddControlCommand.execute(AbsoluteAddControlCommand.java:37)
   at org.eclipse.gef.commands.CommandStack.execute(CommandStack.java:78)
   at com.swtdesigner.gef.DesignerEditDomain$1.execute(DesignerEditDomain.java:36)
   at org.eclipse.gef.tools.AbstractTool.executeCurrentCommand(AbstractTool.java:416)
   at org.eclipse.gef.tools.CreationTool.performCreation(CreationTool.java:198)
   at org.eclipse.gef.tools.CreationTool.handleButtonUp(CreationTool.java:122)
   at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java:1006)
   at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:232)
   at com.swtdesigner.gef.DesignerEditDomain.mouseUp(DesignerEditDomain.java:225)
   at org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouseReleased(DomainEventDispatcher.java:346)
   at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(LightweightSystem.java:511)
   at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:136)
   at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
   at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2772)
   at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2431)
   at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
   at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
   at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
   at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
   at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
   at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
   at org.eclipse.core.launcher.Main.run(Main.java:704)
   at org.eclipse.core.launcher.Main.main(Main.java:688)


Following is the code of the Composite that was added as a Custom composite.

Code: Select all
package examples.forms;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class WindControl extends Composite {

  public WindControl(Composite parent, int style) {
    super(parent, style);
    final FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = 5;
    formLayout.marginHeight = 5;
    setLayout(formLayout);
    FormToolkit toolkit = new FormToolkit(Display.getCurrent());
    toolkit.adapt(this);

    final Label nLabel = toolkit.createLabel(this, "N", SWT.NONE);
    final FormData formData_2 = new FormData();
    formData_2.bottom = new FormAttachment(0, 23);
    formData_2.top = new FormAttachment(0, 6);
    formData_2.left = new FormAttachment(0, 59);
    nLabel.setLayoutData(formData_2);

    final Label eLabel = toolkit.createLabel(this, "E", SWT.NONE);
    final FormData formData = new FormData();
    formData.top = new FormAttachment(0, 52);
    formData.left = new FormAttachment(0, 109);
    formData.bottom = new FormAttachment(0, 69);
    formData.right = new FormAttachment(0, 117);
    eLabel.setLayoutData(formData);

    final Label wLabel = toolkit.createLabel(this, "W", SWT.NONE);
    final FormData formData_3 = new FormData();
    formData_3.top = new FormAttachment(0, 54);
    formData_3.left = new FormAttachment(0, 7);
    wLabel.setLayoutData(formData_3);

    final Label sLabel = toolkit.createLabel(this, "S", SWT.NONE);
    final FormData formData_1 = new FormData();
    formData_1.top = new FormAttachment(0, 106);
    formData_1.left = new FormAttachment(0, 59);
    formData_1.bottom = new FormAttachment(0, 123);
    sLabel.setLayoutData(formData_1);

    final Button button = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_4 = new FormData();
    formData_4.left = new FormAttachment(0, 55);
    formData_4.bottom = new FormAttachment(0, 44);
    formData_4.top = new FormAttachment(0, 25);
    button.setLayoutData(formData_4);

    final Button neButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_5 = new FormData();
    formData_5.left = new FormAttachment(0, 77);
    formData_5.right = new FormAttachment(0, 93);
    formData_5.top = new FormAttachment(0, 32);
    neButton.setLayoutData(formData_5);

    final Button eButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_6 = new FormData();
    formData_6.top = new FormAttachment(0, 52);
    formData_6.left = new FormAttachment(0, 88);
    formData_6.bottom = new FormAttachment(0, 70);
    formData_6.right = new FormAttachment(0, 104);
    eButton.setLayoutData(formData_6);

    final Button seButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_7 = new FormData();
    formData_7.top = new FormAttachment(0, 74);
    formData_7.left = new FormAttachment(0, 77);
    formData_7.bottom = new FormAttachment(0, 93);
    seButton.setLayoutData(formData_7);

    final Button button_4 = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_8 = new FormData();
    formData_8.top = new FormAttachment(0, 85);
    formData_8.left = new FormAttachment(0, 55);
    formData_8.bottom = new FormAttachment(0, 104);
    button_4.setLayoutData(formData_8);

    final Button swButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_9 = new FormData();
    formData_9.right = new FormAttachment(button_4, -5, SWT.LEFT);
    formData_9.bottom = new FormAttachment(seButton, 0, SWT.BOTTOM);
    formData_9.left = new FormAttachment(button_4, -21, SWT.LEFT);
    swButton.setLayoutData(formData_9);

    final Button wButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_10 = new FormData();
    formData_10.top = new FormAttachment(0, 54);
    formData_10.left = new FormAttachment(0, 24);
    formData_10.bottom = new FormAttachment(0, 73);
    wButton.setLayoutData(formData_10);

    final Button button_7 = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_11 = new FormData();
    formData_11.top = new FormAttachment(neButton, 0, SWT.TOP);
    formData_11.left = new FormAttachment(swButton, 0, SWT.LEFT);
    button_7.setLayoutData(formData_11);
    //
  }

  public void dispose() {
    super.dispose();
  }

  protected void checkSubclass() {
  }
}
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

This is a FormToolkit problem

Postby Paul.Helster » Mon Apr 18, 2005 5:31 pm

I created other custom composites. Whenever I try to import them in another composite, I get the same NullPointerException.

These composite are Form based (i.e. their embedded controls are created using the toolkit).

The exception only occurs when a toolkit is used to create the controls embedded in the custom composite that I am trying to add to another composite. If I replace the toolkit.createXXX() with new XXX(), it works fine.

This sounds so easy to reproduce that it looks like I am doing something wrong (i.e. I cannot believe I would be the first one identifying this bug).

Any idea?

Eclipse 3.0.1
SWT-Designer 4.0.0 trial

Paul
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Re: NullPointerException when adding a custom control

Postby Eric Clayberg » Mon Apr 18, 2005 6:28 pm

Paul.Helster wrote:I get a NullPointerException when adding a custom control.

The latest v4.0.1 build corrects the problem.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Paul.Helster » Mon Apr 18, 2005 7:04 pm

Yes it does fix the problem. Thank you. And I am now a registered user :)
Paul.Helster
 
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Eric Clayberg » Mon Apr 18, 2005 7:19 pm

Paul.Helster wrote:Yes it does fix the problem. Thank you. And I am now a registered user :)

Thank you! :-)
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest