Skip to main content



      Home
Home » Eclipse Projects » GEF » NullPointerException when Instanciating
NullPointerException when Instanciating [message #249411] Wed, 24 June 2009 05:10 Go to next message
Eclipse UserFriend
Hi everyone!

i'm having trouble to instantiate a Palette in a my
ScrollingGraphicalViewer.

I followed the steps in the Gef Redbook but when i try to register the
palette at my EditDomain i get a null pointer exception:

java.lang.NullPointerException at
org.eclipse.gef.ui.palette.PaletteViewer.setActiveTool(Palet teViewer.java:381)
at org.eclipse.gef.EditDomain.loadDefaultTool(EditDomain.java:1 92)
at org.eclipse.gef.EditDomain.setPaletteRoot(EditDomain.java:34 3)
at
project.ui.gui.editors.CanvasGefEditor.createPaletteViewer(C anvasGefEditor.java:430)


Here is the createPaletteViewer methode:


private PaletteViewer createPaletteViewer(Composite parent) {
// create graphical viewer
PaletteViewer viewer = new PaletteViewer();
viewer.createControl(parent);

// hook the viewer into the EditDomain (only one palette per
EditDomain)
getEditDomain().setPaletteViewer(viewer);

// important: the palette is initialized via EditDomain
getEditDomain().setPaletteRoot(getPaletteRoot());

return viewer;
}


and here the setActiveTool:

public void setActiveTool(ToolEntry newMode) {
if (newMode == null)
newMode = getPaletteRoot().getDefaultEntry();
if (activeEntry != null)
getToolEntryEditPart(activeEntry).setToolSelected(false);
activeEntry = newMode;
if (activeEntry != null) {
ToolEntryEditPart editpart = getToolEntryEditPart(activeEntry);
editpart.setToolSelected(true);
}
fireModeChanged();
}

So does anybody have a clue?


Thanks in Advance!
Chris
Re: NullPointerException when Instanciating [message #249424 is a reply to message #249411] Wed, 24 June 2009 19:41 Go to previous messageGo to next message
Eclipse UserFriend
Perhaps you are seeing this bug which is fixed in 3.5:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=270028

-Ben

Chris Turner wrote:
> Hi everyone!
>
> i'm having trouble to instantiate a Palette in a my
> ScrollingGraphicalViewer.
>
> I followed the steps in the Gef Redbook but when i try to register the
> palette at my EditDomain i get a null pointer exception:
> java.lang.NullPointerException at
> org.eclipse.gef.ui.palette.PaletteViewer.setActiveTool(Palet teViewer.java:381)
>
> at org.eclipse.gef.EditDomain.loadDefaultTool(EditDomain.java:1 92)
> at org.eclipse.gef.EditDomain.setPaletteRoot(EditDomain.java:34 3)
> at
> project.ui.gui.editors.CanvasGefEditor.createPaletteViewer(C anvasGefEditor.java:430)
>
>
>
> Here is the createPaletteViewer methode:
>
>
> private PaletteViewer createPaletteViewer(Composite parent) {
> // create graphical viewer
> PaletteViewer viewer = new PaletteViewer();
> viewer.createControl(parent);
>
> // hook the viewer into the EditDomain (only one palette per
> EditDomain)
> getEditDomain().setPaletteViewer(viewer);
>
> // important: the palette is initialized via EditDomain
> getEditDomain().setPaletteRoot(getPaletteRoot());
>
> return viewer;
> }
>
>
> and here the setActiveTool:
>
> public void setActiveTool(ToolEntry newMode) {
> if (newMode == null)
> newMode = getPaletteRoot().getDefaultEntry();
> if (activeEntry != null)
> getToolEntryEditPart(activeEntry).setToolSelected(false);
> activeEntry = newMode;
> if (activeEntry != null) {
> ToolEntryEditPart editpart = getToolEntryEditPart(activeEntry);
> editpart.setToolSelected(true);
> }
> fireModeChanged();
> }
>
> So does anybody have a clue?
>
>
> Thanks in Advance! Chris
Re: NullPointerException when Instanciating [message #249426 is a reply to message #249411] Thu, 25 June 2009 23:32 Go to previous message
Eclipse UserFriend
Hi,

Set palette root before you set the palette for edit domain. When you set
the palette viewer for the edit domain palette viewer has no contents - no
editparts, so you get an NPE. Set the palette root on the palette viewer
and the attach to the domain.

Cheers,
Alex
Previous Topic:[Announce] GEF 3.5.0 is available
Next Topic:Shapes Exanple in a View with auto layout
Goto Forum:
  


Current Time: Sun Jul 06 11:24:10 EDT 2025

Powered by FUDForum. Page generated in 0.04907 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top