Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to instantiate new Preference page
How to instantiate new Preference page [message #234224] Mon, 26 April 2004 00:30 Go to next message
Eclipse UserFriend
Originally posted by: no.ddress.here

Developing a plugin using 3M8 - the new view is working fine - and now
trying to add a preferences page.

Whenever I try to open my preferences page, which is properly listed
under Windows|Preferences, I get an "unable to instantiate" message for
my preferences page when I run the plugin in the Run-time Workbench.

To check my work, I created a completely new "test" plug-in project
using the view wizard template, then used the New Extension point wizard
to add a sample extension to org.eclipse.ui.preferencePages

When I run that, I get the same error dialog with same message (only the
name of the plug-in is different):

Plug-in "test" was unable to instantiate class
"test.preferences.SamplePreferencePage".

What more do I have to do to enable the plug-in to instantiate the
preference page class?

Thanks,
Gerald





!SESSION Apr 25, 2004 17:06:27.120
---------------------------------------------
java.version=1.4.2_04
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
!ENTRY org.eclipse.core.runtime 4 1 Apr 25, 2004 17:06:27.120
!MESSAGE Plug-in "test" was unable to instantiate class
"test.preferences.SamplePreferencePage".
!STACK 0
java.lang.NullPointerException
at test.preferences.SamplePreferencePage.<init>
(SamplePreferencePage.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e
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:2 74)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at
org.eclipse.core.internal.registry.ConfigurationElement.crea teExecutable
Extension(ConfigurationElement.java:140)
at
org.eclipse.core.internal.registry.ConfigurationElement.crea teExecutable
Extension(ConfigurationElement.java:125)
at
org.eclipse.core.internal.registry.ConfigurationElement.crea teExecutable
Extension(ConfigurationElement.java:114)
at org.eclipse.ui.internal.WorkbenchPlugin$1.run
(WorkbenchPlugin.java:189)
at org.eclipse.swt.custom.BusyIndicator.showWhile
(BusyIndicator.java:84)
at org.eclipse.ui.internal.WorkbenchPlugin.createExtension
(WorkbenchPlugin.java:186)
at
org.eclipse.ui.internal.dialogs.WorkbenchPreferenceNode.crea tePage
(WorkbenchPreferenceNode.java:60)
at org.eclipse.jface.preference.PreferenceDialog.showPage
(PreferenceDialog.java:982)
at org.eclipse.jface.preference.PreferenceDialog
$9.selectionChanged(PreferenceDialog.java:570)
at org.eclipse.jface.viewers.StructuredViewer$3.run
(StructuredViewer.java:431)
at org.eclipse.core.internal.runtime.InternalPlatform.run
(InternalPlatform.java:610)
at org.eclipse.core.runtime.Platform.run(Platform.java:521)
at
org.eclipse.jface.viewers.StructuredViewer.firePostSelection Changed
(StructuredViewer.java:429)
at org.eclipse.jface.viewers.StructuredViewer.handlePostSelect
(StructuredViewer.java:680)
at org.eclipse.jface.viewers.StructuredViewer$5.widgetSelected
(StructuredViewer.java:698)
at org.eclipse.jface.util.OpenStrategy.firePostSelectionEvent
(OpenStrategy.java:198)
at org.eclipse.jface.util.OpenStrategy.access$4
(OpenStrategy.java:193)
at org.eclipse.jface.util.OpenStrategy$3.run
(OpenStrategy.java:334)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages
(Synchronizer.java:106)
at org.eclipse.swt.widgets.Display.runAsyncMessages
(Display.java:2555)
at org.eclipse.swt.widgets.Display.readAndDispatch
(Display.java:2260)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:670 )
at org.eclipse.jface.window.Window.open(Window.java:650)
at org.eclipse.ui.internal.OpenPreferencesAction.run
(OpenPreferencesAction.java:72)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:881 )
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection
(ActionContributionItem.java:550)
at org.eclipse.jface.action.ActionContributionItem.access$2
(ActionContributionItem.java:502)
at org.eclipse.jface.action.ActionContributionItem$5.handleEven t
(ActionContributionItem.java:435)
at org.eclipse.swt.widgets.EventTable.sendEvent
(EventTable.java:82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:769)
at org.eclipse.swt.widgets.Display.runDeferredEvents
(Display.java:2578)
at org.eclipse.swt.widgets.Display.readAndDispatch
(Display.java:2256)
at org.eclipse.ui.internal.Workbench.runEventLoop
(Workbench.java:1562)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1536)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench
(Workbench.java:257)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench
(PlatformUI.java:139)
at org.eclipse.ui.internal.ide.IDEApplication.run
(IDEApplication.java:90)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run
(PlatformActivator.java:277)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:239)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:117)
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:267)
at org.eclipse.core.launcher.Main.run(Main.java:692)
at org.eclipse.core.launcher.Main.main(Main.java:676)
Re: How to instantiate new Preference page [message #234319 is a reply to message #234224] Mon, 26 April 2004 07:56 Go to previous messageGo to next message
Michael Keppler is currently offline Michael KepplerFriend
Messages: 164
Registered: July 2009
Senior Member
Gerald B. Rosenberg schrieb:
> To check my work, I created a completely new "test" plug-in project
> using the view wizard template, then used the New Extension point wizard
> to add a sample extension to org.eclipse.ui.preferencePages
>
> When I run that, I get the same error dialog with same message (only the
> name of the plug-in is different):
>
> Plug-in "test" was unable to instantiate class
> "test.preferences.SamplePreferencePage".

I assume you forgot to provide the default values for your preferences
in the preference store. At least that was the reason for me getting the
same error during development of some plugins. :)

Have a look at
http://www.eclipse.org/articles/Article-Preferences/preferen ces.htm
and concentrate on the section "The Preference Store and the Plug-in" of
that article to set default values.

Ciao, Michael.
Re: How to instantiate new Preference page [message #235210 is a reply to message #234224] Tue, 27 April 2004 12:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: th.michel.gmx.net

Am Sun, 25 Apr 2004 17:30:51 -0700 schrieb Gerald B. Rosenberg:

> Developing a plugin using 3M8 - the new view is working fine - and now
> trying to add a preferences page.
>
> Whenever I try to open my preferences page, which is properly listed
> under Windows|Preferences, I get an "unable to instantiate" message for
> my preferences page when I run the plugin in the Run-time Workbench.
>
> To check my work, I created a completely new "test" plug-in project
> using the view wizard template, then used the New Extension point wizard
> to add a sample extension to org.eclipse.ui.preferencePages
>
> When I run that, I get the same error dialog with same message (only the
> name of the plug-in is different):
>
> Plug-in "test" was unable to instantiate class
> "test.preferences.SamplePreferencePage".
>
> What more do I have to do to enable the plug-in to instantiate the
> preference page class?
>
> Thanks,
> Gerald
>
Hi,

i think any error in the init of preference page would cause this message.
So i would like set a breakpoint at the begin of any implements method by
you. Then start the runtime-workbench for debug mode.
Maybe you have forgotten a dependency of your plugin, then the needed
import could not be found and the object could not be instanciate. Or you
have really a NullPointer in your methods...
To create a preference page you need:
1) implements extention point
2) create a class wich is subclass of PreferencePage and implements
IWorkbenchPreferencePage
3) implements the methods init(Workbench), createContents(Composite)

I hope it was usefull Thomas
Re: How to instantiate new Preference page [message #235272 is a reply to message #234319] Tue, 27 April 2004 14:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no.ddress.here

In article <c6ieus$5to$1@eclipse.org>, michael.keppler@gmx.de says...
> Gerald B. Rosenberg schrieb:
> > To check my work, I created a completely new "test" plug-in project
> > using the view wizard template, then used the New Extension point wizard
> > to add a sample extension to org.eclipse.ui.preferencePages
> >
> > When I run that, I get the same error dialog with same message (only the
> > name of the plug-in is different):
> >
> > Plug-in "test" was unable to instantiate class
> > "test.preferences.SamplePreferencePage".
>
> I assume you forgot to provide the default values for your preferences
> in the preference store. At least that was the reason for me getting the
> same error during development of some plugins. :)
>
> Have a look at
> http://www.eclipse.org/articles/Article-Preferences/preferen ces.htm
> and concentrate on the section "The Preference Store and the Plug-in" of
> that article to set default values.
>
> Ciao, Michael.
>

Yes, I did not have the defaults set. Unfortunately, correcting that
did not solve my problem (but it may have solved my next problem).

Thanks,
Gerald
Re: How to instantiate new Preference page [message #235304 is a reply to message #235210] Tue, 27 April 2004 14:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no.ddress.here

In article <pan.2004.04.27.12.56.57.138029@gmx.net>, th.michel@gmx.net
says...
>
> i think any error in the init of preference page would cause this message.
> So i would like set a breakpoint at the begin of any implements method by
> you. Then start the runtime-workbench for debug mode.
> Maybe you have forgotten a dependency of your plugin, then the needed
> import could not be found and the object could not be instanciate. Or you
> have really a NullPointer in your methods...
> To create a preference page you need:
> 1) implements extention point
> 2) create a class wich is subclass of PreferencePage and implements
> IWorkbenchPreferencePage
> 3) implements the methods init(Workbench), createContents(Composite)
>
> I hope it was usefull Thomas
>

Comments helped trace the problems to a NPE. My preference page
constructor follows the standard pattern, but fails at the point of
trying to retrieve the preferenceStore. Here is the actual code:

public class PreferencePage extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {

public static final String SAVE_STUFF = "savestuff";

public PreferencePage() {
super(GRID);
DocPrecisionPlugin x = DocPrecisionPlugin.getDefault();
// !!!! At this point x is null !!!!!
setPreferenceStore(DocPrecisionPlugin
.getDefault().getPreferenceStore());
setDescription("Construction Helper");
initializeDefaults();
}
.....

The DocPrecisionPlugin.getDefault() method does run, but the breakpoint
on the DocPrecisionPlugin class constructor -- which is where the value
returned by the getDefault method is set -- is never caught by the
debugger.

Meaning that the DocPrecisionPlugin class is not being instantiated
before the workbench tries to instantiate my preferences page? Is there
something I need to do/set to have my DocPrecisionPlugin class
instantiated automatically?

Thanks,
Gerald
Re: EVIL MANIFEST FILE! (was How to instantiate new Preference page ) [message #235639 is a reply to message #235304] Wed, 28 April 2004 03:18 Go to previous message
Eclipse UserFriend
Originally posted by: no.ddress.here

FWIW, turns out to have been the mere existance of the wizard generated
meta-inf/Manifest.mf file. Simply removing that file allowed my nascent
plugin preference pages to run without any problem.

Anyone know what the manifest is for and why it would, as generated,
prevent my main plugin class from being instantiated prior to the
preference page from being called?

Thanks to Michael and Thomas.



In article <MPG.1af80f88b34f5414989683@news.eclipse.org>, no@ddress.here
says...
> In article <pan.2004.04.27.12.56.57.138029@gmx.net>, th.michel@gmx.net
> says...
> >
> > i think any error in the init of preference page would cause this message.
> > So i would like set a breakpoint at the begin of any implements method by
> > you. Then start the runtime-workbench for debug mode.
> > Maybe you have forgotten a dependency of your plugin, then the needed
> > import could not be found and the object could not be instanciate. Or you
> > have really a NullPointer in your methods...
> > To create a preference page you need:
> > 1) implements extention point
> > 2) create a class wich is subclass of PreferencePage and implements
> > IWorkbenchPreferencePage
> > 3) implements the methods init(Workbench), createContents(Composite)
> >
> > I hope it was usefull Thomas
> >
>
> Comments helped trace the problems to a NPE. My preference page
> constructor follows the standard pattern, but fails at the point of
> trying to retrieve the preferenceStore. Here is the actual code:
>
> public class PreferencePage extends FieldEditorPreferencePage implements
> IWorkbenchPreferencePage {
>
> public static final String SAVE_STUFF = "savestuff";
>
> public PreferencePage() {
> super(GRID);
> DocPrecisionPlugin x = DocPrecisionPlugin.getDefault();
> // !!!! At this point x is null !!!!!
> setPreferenceStore(DocPrecisionPlugin
> .getDefault().getPreferenceStore());
> setDescription("Construction Helper");
> initializeDefaults();
> }
> ....
>
> The DocPrecisionPlugin.getDefault() method does run, but the breakpoint
> on the DocPrecisionPlugin class constructor -- which is where the value
> returned by the getDefault method is set -- is never caught by the
> debugger.
>
> Meaning that the DocPrecisionPlugin class is not being instantiated
> before the workbench tries to instantiate my preferences page? Is there
> something I need to do/set to have my DocPrecisionPlugin class
> instantiated automatically?
>
> Thanks,
> Gerald
>
Previous Topic:How to get the package name of the JavaProject?
Next Topic:[5TH Post] Having dual/extended IEditorInput ? in JavaEditor Example
Goto Forum:
  


Current Time: Thu Apr 25 14:47:14 GMT 2024

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

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

Back to the top