NPE from Swing Designer

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

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

NPE from Swing Designer

Postby Doug Beyer » Mon Jan 31, 2005 1:45 pm

I'm using the trial version of WindowBuilder. Several times now I've finished making manual changes to the source (externally from eclipse using another editor), and when I go back to the designer and attempt to go to Design mode, I get a NullPointerException.

Can someone tell me what aspects of the source code should not be tampered with manually? Has anyone else seen these NPE's?
Doug Beyer
 

Re: NPE from Swing Designer

Postby Eric Clayberg » Tue Feb 01, 2005 5:37 am

Doug Beyer wrote:I'm using the trial version of WindowBuilder. Several times now I've finished making manual changes to the source (externally from eclipse using another editor), and when I go back to the designer and attempt to go to Design mode, I get a NullPointerException.

Can you be more specific?

Exactly what exception appears in your Eclipse ".log" file?

What version of Designer are you using? Please make sure that you are using the latest v3.0.1 build rather than any previous version.

Can you send us the source for the window you are editing so that we can attempt to reproduce the problem?

Doug Beyer wrote:Can someone tell me what aspects of the source code should not be tampered with manually?

In general, you can "tamper" with any aspects of the source as Designer is very resilient in the face of user changes and refactorings.

We would need to see what exact problem was triggered by your code to determine whether it represents a case that we should reasonably expect to handle.

Doug Beyer wrote:Has anyone else seen these NPE's?

Without any information about the NPE itself, that would be impossible to say.
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 Guest » Tue Feb 01, 2005 7:18 am

I've gotten the problem on several files. All the files build ok in Ant and Eclipse, and the app runs ok.

Sorry for putting the following in the email body but I didn't see any way to add attachments to this email.

Interesting... After upgrading to WindowBuilder 3.0.1, I was able to open one of the files that was breaking before. But I still can't open the file that's included at the bottom of this email.

After installing WindowBuilder 3.0.1, I deleted Eclipse's "configuration" directory and built the project from within Eclipse. Then I attempted to open this form and got the following exception.

Exception
---------

!ENTRY com.swtdesigner 4 4 Feb 01, 2005 07:13:12.341
!MESSAGE Designer internal error: com.swtdesigner.properties.PropertyException: java.lang.NullPointerException
!STACK 0
com.swtdesigner.properties.PropertyException: com.swtdesigner.properties.PropertyException: java.lang.

NullPointerException
at com.swtdesigner.model.swing.component.ComponentBeanInfo.prepareControl(ComponentBeanInfo.java:483)
at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5470)
at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(JavaInfo.java:5453)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.handleRootNodeSelected(

DesignerEditorPropertyComposite.java:492)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.updatePropertyComposite(

DesignerEditorPropertyComposite.java:644)
at com.swtdesigner.gef.DesignerEditor.parseCompilationUnit(DesignerEditor.java:756)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:659)
at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:627)
at com.swtdesigner.editors.MultiPageEditor.showDesignEditor(MultiPageEditor.java:291)
at com.swtdesigner.editors.MultiPageEditor$2.widgetSelected(MultiPageEditor.java:159)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
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.Widget.sendEvent(Widget.java:820)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:805)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:613)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3053)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1917)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:287)
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(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
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)
Caused by: com.swtdesigner.properties.PropertyException: java.lang.NullPointerException
at com.swtdesigner.model.swing.component.ComponentBeanInfo.prepareControl(ComponentBeanInfo.java:483)
at com.swtdesigner.model.swing.component.ContainerBeanInfo.createControl(ContainerBeanInfo.java:360)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.prepareControl(ComponentBeanInfo.java:446)
... 37 more
Caused by: java.lang.NullPointerException
at com.swtdesigner.model.swing.layouts.managers.LayoutManagerInfo.addComponent(LayoutManagerInfo.java:

264)
at com.swtdesigner.model.swing.layouts.managers.LayoutManagerInfo.addComponent(LayoutManagerInfo.java:

260)
at com.swtdesigner.model.swing.component.ContainerBeanInfo.createControl(ContainerBeanInfo.java:414)
at com.swtdesigner.model.swing.component.ComponentBeanInfo.prepareControl(ComponentBeanInfo.java:446)
... 39 more


Form source
-----------

/*
* Created on Jan 31, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.dbeyer.cim.browser.ui;

import com.dbeyer.cim.browser.ui.treemodel.TreeModelCimClass;
import com.uxcomm.cim.cimom.ExceptionCimom;
import com.uxcomm.cim.cimom.ICimom;
import com.uxcomm.cim.schema.ExceptionCimSchema;
import com.uxcomm.cim.schema.IClassName;


import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.text.MessageFormat;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;



/**
* @author dbeyer
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class MainForm extends JFrame {


public MainForm() {
super();
setResizable(false);
final MainForm mainForm = this;
final Container contentPane = getContentPane();
m_Layout = new CardLayout();
contentPane.setLayout(m_Layout);
setSize(new Dimension(800, 600));
setTitle("CIM Browser 1.0");
setBounds(100, 100, 640, 531);

// DSB, 01/25/2005 - Interesting... Repainting to the Window's look and feel didn't seem to work
// until after I had set the frame's caption below. This was the case even after calling
// SwingUtilities.updateComponentTreeUI( this ). Maybe I needed to explicitly invalidate the entire
// frame?
try
{
UIManager.setLookAndFeel( LOOK_AND_FEEL_WINDOWS );
SwingUtilities.updateComponentTreeUI( this );
}
catch( Exception e )
{
System.out.println( "Unable to set look and feel: " + e.getMessage() );
; // Ignore it and use the default look and feel.
}

JFrame.setDefaultLookAndFeelDecorated( true );

// I want to explicitly control the "close" behaviour. See processWindowEvent() override.
setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );

final JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);

final JMenu menu = new JMenu();
menu.setMnemonic(KeyEvent.VK_F);
menuBar.add(menu);
menu.setText("File");

final JMenuItem menuItem = new JMenuItem();
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
processWindowEvent( new WindowEvent( mainForm, WindowEvent.WINDOW_CLOSING ) );
}
});
menuItem.setMnemonic(KeyEvent.VK_X);
menu.add(menuItem);
menuItem.setText("Exit");

final JMenu menu_1 = new JMenu();
menu_1.setMnemonic(KeyEvent.VK_Q);
menuBar.add(menu_1);
menu_1.setText("Query");

final JMenuItem menuItem_1 = new JMenuItem();
menuItem_1.setMnemonic(KeyEvent.VK_D);
menu_1.add(menuItem_1);
menuItem_1.setText("Toggle Definition...");
menuItem_1.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_D,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
false ) );
menuItem_1.addActionListener(
new ActionListener()
{
public void actionPerformed( final ActionEvent e )
{
toggleQueryDefView();
}
} );

final JMenuItem m_ExecMenuItem = new JMenuItem();
m_ExecMenuItem.setMnemonic(KeyEvent.VK_E);
menu_1.add(m_ExecMenuItem);
m_ExecMenuItem.setText("Execute");
m_ExecMenuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_E,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
false ) );
m_ExecMenuItem.addActionListener(
new ActionListener()
{
public void actionPerformed( final ActionEvent e )
{
mainForm.executeQuery();
}
} );

m_CimTree = new JTree( getEmptyDisplayRootNode() );
m_CimTree.setCellRenderer( TreeModelCimClass.getCellRenderer() );
m_QueryDefinitionPanel = new QueryDefinitionPanel();
contentPane.add( m_QueryDefinitionPanel, KEY_COMP_DEFINE_QUERY );
contentPane.add( new JScrollPane( m_CimTree ), KEY_COMP_EXEC_RESULTS );

toggleQueryDefView();
//
}


///////////////////////////////////////////////////////////////////////////////////////////
// Protected attributes.

protected void processWindowEvent
(
final WindowEvent e
)
{
if ( WindowEvent.WINDOW_CLOSING == e.getID() )
{
int exit = UiUtil.showConfirmDlg( this, "Exit the application?" );
if ( JOptionPane.YES_OPTION == exit )
System.exit( 0 );
}
else
super.processWindowEvent( e );
}


///////////////////////////////////////////////////////////////////////////////////////////
// Private attributes.

private final String LOOK_AND_FEEL_WINDOWS = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private final String KEY_COMP_DEFINE_QUERY = "querydef";
private final String KEY_COMP_EXEC_RESULTS = "execresults";
private final String CLAUSE_QUERY_DEF = "[Query Definition]";
private final String CLAUSE_RESULTS = "[Query Results]";
private final String APP_NAME_ROOT = "CIM Browser 1.0 - {0}";
private final String APP_NAME_QUERY_DEF = MessageFormat.format( APP_NAME_ROOT, new Object[] {

CLAUSE_QUERY_DEF } );
private final String APP_NAME_RESULTS = MessageFormat.format( APP_NAME_ROOT, new Object[] {

CLAUSE_RESULTS } );

private CardLayout m_Layout;
private JTree m_CimTree;
private QueryDefinitionPanel m_QueryDefinitionPanel;

// A 'false' initial value is important as toggleQueryDefView() is called at form creation and we want
// the query def view to show at app startup.
private boolean m_QueryDefIsShowing = false;




private MutableTreeNode getEmptyDisplayRootNode()
{
return new DefaultMutableTreeNode( "No items to display." );
}


private void toggleQueryDefView()
{
String viewToShow = ( m_QueryDefIsShowing ? KEY_COMP_EXEC_RESULTS : KEY_COMP_DEFINE_QUERY );
m_QueryDefIsShowing = !m_QueryDefIsShowing;
setTitle( m_QueryDefIsShowing ? APP_NAME_QUERY_DEF : APP_NAME_RESULTS );
m_Layout.show( getContentPane(), viewToShow );
}


private void showQueryResultView()
{
m_QueryDefIsShowing = false;
setTitle( APP_NAME_RESULTS );
m_Layout.show( getContentPane(), KEY_COMP_EXEC_RESULTS );
}


private void executeQuery()
{
try
{
m_QueryDefinitionPanel.validateDefinition();
}
catch( Exception e )
{
UiUtil.showWarningDlg( this, e.getMessage() );
return;
}

try
{
m_QueryDefinitionPanel.initCimom();
}
catch( Exception e )
{
UiUtil.showErrorDlg( this, e.getMessage() );
return;
}

EnumExecMethod execMethod = m_QueryDefinitionPanel.getMethod();
String className = m_QueryDefinitionPanel.getClassName();
String namespace = m_QueryDefinitionPanel.getNamespace();
boolean localOnly = m_QueryDefinitionPanel.getLocalOnly();
boolean deepInheritance = m_QueryDefinitionPanel.getDeepInheritance();
boolean inclClassOrigin = m_QueryDefinitionPanel.getIncludeClassOrigin();
boolean inclQualifiers = m_QueryDefinitionPanel.getIncludeQualifiers();
List wantedProps = m_QueryDefinitionPanel.getWantedProperties();

Object queryResult;
try
{
queryResult = execMethod( execMethod,
namespace,
className,
localOnly,
deepInheritance,
inclQualifiers,
inclClassOrigin,
wantedProps );
paintQueryResult( namespace, queryResult );
showQueryResultView();
}
catch( Exception e )
{
UiUtil.showErrorDlg( this, e.getMessage() );
}
}


private Object execMethod
(
final EnumExecMethod methodFlag,
final String namespace,
final String className,
final boolean localOnly,
final boolean deepInheritance,
final boolean inclQualifiers,
final boolean inclClassOrigin,
final List wantedProps
) throws ExceptionCimom, ExceptionCimSchema
{
ICimom cimom = com.uxcomm.cim.cimom.Factory.getCimom();
assert null != cimom ;

IClassName cn = com.uxcomm.cim.schema.Factory.getClassName( className );

if ( EnumExecMethod.GET_CLASS == methodFlag )
return cimom.getClass( namespace, cn, localOnly, inclQualifiers, inclQualifiers, wantedProps );

else if ( EnumExecMethod.ENUM_CLASSES == methodFlag )
return cimom.enumerateClasses( namespace, cn, deepInheritance, localOnly, inclQualifiers, inclQualifiers );

else if ( EnumExecMethod.ENUM_CLASS_NAMES == methodFlag )
return cimom.enumerateClassNames( namespace, cn, deepInheritance );

else if ( EnumExecMethod.GET_ANCESTOR_CLASSES == methodFlag )
return cimom.getAncestorClasses( namespace, cn );

else if ( EnumExecMethod.GET_INSTANCE == methodFlag )
{
// **TODO**: DSB, 01/29/2005 - Not implemented yet.
return null;
}
else if ( EnumExecMethod.ENUM_INSTANCES == methodFlag )
{
// **TODO**: DSB, 01/29/2005 - Not implemented yet.
return null;
}
else if ( EnumExecMethod.ENUM_INSTANCE_NAMES == methodFlag )
{
// **TODO**: DSB, 01/29/2005 - Not implemented yet.
return null;
}
else
throw new RuntimeException( "Unexpected execution method." );
}


private void paintQueryResult
(
final String namespace,
final Object queryResult
)
{
TreeModelCimClass cimTreeModel = new TreeModelCimClass( namespace, queryResult );
m_CimTree.setModel( cimTreeModel );
}



}
Guest
 

Postby Eric Clayberg » Mon Feb 07, 2005 2:18 pm

Anonymous wrote:Sorry for putting the following in the email body but I didn't see any way to add attachments to this email.

I would suggest just e-mailing them to wb-support@instantiations.com.

Anonymous wrote:Interesting... After upgrading to WindowBuilder 3.0.1, I was able to open one of the files that was breaking before. But I still can't open the file that's included at the bottom of this email.

A new v3.0.1 build (2005.02.07) is available that corrects the problem with this example class.
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 Swing Designer

Who is online

Users browsing this forum: Google [Bot] and 1 guest