I'm using windowbuilder 8.0 on eclipse 3.6.
I have a problem inheriting a panel with CardLayout layout manager.
I've put 3 panels inside the card layout, each with its own label saying "panel n" (1 to 3).
Lazy initializing createContents() is this:
- Code: Select all
private void createContents() {
setLayout(new CardLayout(0, 0));
add(getPanel1(), "name_21037014706136");
add(getPanel2(), "name_21071317321293");
add(getPanel3(), "name_21084236084791");
}
Then I replace "name_2103....." with these:
- Code: Select all
private void createContents() {
setLayout(new CardLayout(0, 0));
add(getPanel1(), getPanel1().getName());
add(getPanel2(), getPanel2().getName());
add(getPanel3(), getPanel3().getName());
}
and assign a name to each panel by using their variable name in the designer; e.g. for panel1 code is:
- Code: Select all
public JPanel getPanel1() {
if (panel1 == null) {
panel1 = new JPanel();
panel1.setLayout(new BorderLayout(0, 0));
panel1.add(getLblPanel1(), BorderLayout.CENTER);
panel1.setName("panel1");
}
return panel1;
}
I do this in order to change selected panel programmatically, for instance, to switch to panel1 programmatically I call this:
- Code: Select all
public void setSelectedPanel(JPanel p) {
((CardLayout)this.getLayout()).show(this, p.getName());
}
Then I inherit from this panel and try to override getPanel1() with a new lazy initializing method:
- Code: Select all
@Override
public JPanel getPanel1() {
if (newPanel1 == null) {
newPanel1 = new JPanel();
newPanel1.setLayout(new BorderLayout(0, 0));
newPanel1.add(getLblNewpanel(), BorderLayout.CENTER);
}
return newPanel1;
}
but designer dont work anymore and say this:
Exception during 'super' constructor evaluation
An exception happened during evaluation of constructor BasePanel() using arguments {}.
java.lang.NullPointerException
at com.BasePanel.createContents(BasePanel.java:34)
at com.BasePanel.<init>(BasePanel.java:22)
at com.BasePanel$$EnhancerByCGLIB$$2f752095.<init>(<generated>)
Show stack trace.
Hide stack trace.
Stack trace:
com.instantiations.designer.core.utils.exception.DesignerException: 313 (Exception during 'super' constructor evaluation). BasePanel() {} java.lang.NullPointerException
at com.BasePanel.createContents(BasePanel.java:34)
at com.BasePanel.<init>(BasePanel.java:22)
at com.BasePanel$$EnhancerByCGLIB$$2f752095.<init>(<generated>)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create(ThisCreationSupport.java:241)
at com.instantiations.designer.core.model.JavaInfoEvaluationHelper.evaluateJavaInfoUsingCreationSupport(JavaInfoEvaluationHelper.java:600)
at com.instantiations.designer.core.parser.JavaInfoParser.addJavaInfo(JavaInfoParser.java:1167)
at com.instantiations.designer.core.parser.JavaInfoParser.parse(JavaInfoParser.java:231)
at com.instantiations.designer.core.parser.JavaInfoParser.access$9(JavaInfoParser.java:216)
at com.instantiations.designer.core.parser.JavaInfoParser$1.runObject(JavaInfoParser.java:137)
at com.instantiations.designer.core.parser.JavaInfoParser$1.runObject(JavaInfoParser.java:1)
at com.instantiations.designer.core.utils.execution.ExecutionUtils.runDesignTime(ExecutionUtils.java:133)
at com.instantiations.designer.core.parser.JavaInfoParser.parse(JavaInfoParser.java:135)
at com.instantiations.designer.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:408)
at com.instantiations.designer.core.editor.DesignPage.access$10(DesignPage.java:400)
at com.instantiations.designer.core.editor.DesignPage$7$1.run(DesignPage.java:337)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4584)
at com.instantiations.designer.core.editor.DesignPage$7.run(DesignPage.java:334)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
at com.instantiations.designer.core.editor.DesignPage.internal_refreshGEF_withProgress(DesignPage.java:355)
at com.instantiations.designer.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:304)
at com.instantiations.designer.core.editor.UndoManager.refreshDesignerEditor(UndoManager.java:362)
at com.instantiations.designer.core.editor.DesignPage.refreshGEF(DesignPage.java:290)
at com.instantiations.designer.core.editor.DesignPage$4.run(DesignPage.java:230)
at com.instantiations.designer.core.utils.execution.ExecutionUtils.runLog(ExecutionUtils.java:86)
at com.instantiations.designer.core.editor.DesignPage.checkDependenciesOnDesignPageActivation(DesignPage.java:225)
at com.instantiations.designer.core.editor.DesignPage.handleActiveState_True(DesignPage.java:213)
at com.instantiations.designer.core.editor.DesignPage.handleActiveState(DesignPage.java:197)
at com.instantiations.designer.core.editor.multi.DefaultMultiMode.showPage(DefaultMultiMode.java:80)
at com.instantiations.designer.core.editor.multi.MultiPagesMode.switchSourceDesign(MultiPagesMode.java:54)
at com.instantiations.designer.core.editor.actions.SwitchAction.run(SwitchAction.java:21)
at com.instantiations.designer.core.editor.actions.EditorRelatedAction.run(EditorRelatedAction.java:40)
at org.eclipse.ui.internal.handlers.ActionDelegateHandlerProxy.execute(ActionDelegateHandlerProxy.java:289)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:468)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:786)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:885)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:567)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:508)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:123)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1253)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1103)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1099)
at org.eclipse.swt.widgets.Widget.wmKeyDown(Widget.java:1808)
at org.eclipse.swt.widgets.Control.WM_KEYDOWN(Control.java:4496)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4191)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4886)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2459)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3655)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.NullPointerException-->null
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220)
at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:639)
at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:304)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create_usingCGLib(ThisCreationSupport.java:277)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create0(ThisCreationSupport.java:254)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create(ThisCreationSupport.java:234)
... 77 more
Caused by: java.lang.NullPointerException
at com.BasePanel.createContents(BasePanel.java:34)
at com.BasePanel.<init>(BasePanel.java:22)
at com.BasePanel$$EnhancerByCGLIB$$2f752095.<init>(<generated>)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:228)
... 86 more
Full context stack trace:
com.instantiations.designer.core.utils.exception.DesignerException: 313 (Exception during 'super' constructor evaluation). BasePanel() {} java.lang.NullPointerException
at com.BasePanel.createContents(BasePanel.java:34)
at com.BasePanel.<init>(BasePanel.java:22)
at com.BasePanel$$EnhancerByCGLIB$$2f752095.<init>(<generated>)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create(ThisCreationSupport.java:241)
at com.instantiations.designer.core.model.JavaInfoEvaluationHelper.evaluateJavaInfoUsingCreationSupport(JavaInfoEvaluationHelper.java:600)
at com.instantiations.designer.core.parser.JavaInfoParser.addJavaInfo(JavaInfoParser.java:1167)
at com.instantiations.designer.core.parser.JavaInfoParser.parse(JavaInfoParser.java:231)
at com.instantiations.designer.core.parser.JavaInfoParser.access$9(JavaInfoParser.java:216)
at com.instantiations.designer.core.parser.JavaInfoParser$1.runObject(JavaInfoParser.java:137)
at com.instantiations.designer.core.parser.JavaInfoParser$1.runObject(JavaInfoParser.java:1)
at com.instantiations.designer.core.utils.execution.ExecutionUtils.runDesignTime(ExecutionUtils.java:133)
at com.instantiations.designer.core.parser.JavaInfoParser.parse(JavaInfoParser.java:135)
at com.instantiations.designer.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:408)
at com.instantiations.designer.core.editor.DesignPage.access$10(DesignPage.java:400)
at com.instantiations.designer.core.editor.DesignPage$7$1.run(DesignPage.java:337)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4584)
at com.instantiations.designer.core.editor.DesignPage$7.run(DesignPage.java:334)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
at com.instantiations.designer.core.editor.DesignPage.internal_refreshGEF_withProgress(DesignPage.java:355)
at com.instantiations.designer.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:304)
at com.instantiations.designer.core.editor.UndoManager.refreshDesignerEditor(UndoManager.java:362)
at com.instantiations.designer.core.editor.DesignPage.refreshGEF(DesignPage.java:290)
at com.instantiations.designer.core.editor.DesignPage$4.run(DesignPage.java:230)
at com.instantiations.designer.core.utils.execution.ExecutionUtils.runLog(ExecutionUtils.java:86)
at com.instantiations.designer.core.editor.DesignPage.checkDependenciesOnDesignPageActivation(DesignPage.java:225)
at com.instantiations.designer.core.editor.DesignPage.handleActiveState_True(DesignPage.java:213)
at com.instantiations.designer.core.editor.DesignPage.handleActiveState(DesignPage.java:197)
at com.instantiations.designer.core.editor.multi.DefaultMultiMode.showPage(DefaultMultiMode.java:80)
at com.instantiations.designer.core.editor.multi.MultiPagesMode.switchSourceDesign(MultiPagesMode.java:54)
at com.instantiations.designer.core.editor.actions.SwitchAction.run(SwitchAction.java:21)
at com.instantiations.designer.core.editor.actions.EditorRelatedAction.run(EditorRelatedAction.java:40)
at org.eclipse.ui.internal.handlers.ActionDelegateHandlerProxy.execute(ActionDelegateHandlerProxy.java:289)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:468)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:786)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:885)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:567)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:508)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:123)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1253)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1103)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1099)
at org.eclipse.swt.widgets.Widget.wmKeyDown(Widget.java:1808)
at org.eclipse.swt.widgets.Control.WM_KEYDOWN(Control.java:4496)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4191)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4886)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2459)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3655)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.NullPointerException-->null
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220)
at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:639)
at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:304)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create_usingCGLib(ThisCreationSupport.java:277)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create0(ThisCreationSupport.java:254)
at com.instantiations.designer.core.model.creation.ThisCreationSupport.create(ThisCreationSupport.java:234)
... 77 more
Caused by: java.lang.NullPointerException
at com.BasePanel.createContents(BasePanel.java:34)
at com.BasePanel.<init>(BasePanel.java:22)
at com.BasePanel$$EnhancerByCGLIB$$2f752095.<init>(<generated>)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:228)
... 86 more
The line where the NullPointerException raises is this (from method createContents()):
- Code: Select all
add(getPanel1(), getPanel1().getName());
finally if I replace it with the old one:
- Code: Select all
add(getPanel1(), "name_21037014706136");
everything works fine..
Is there a way to have my code work? Or is there another way to change the selected panel programmatically, allowing me not to set the panel name and then allowing me to leave the genereted code "as is" with "name_21037014706136" in method add()?
thanks
Luca