0

我正在尝试在工具栏上添加 NewCSSWizard。为此,我使用了 Platform Command Framework,添加了命令和处理程序扩展点。扩展 WizardHandler 但它不起作用并抛出 NPE。如果在方法 executeHandler(ExecutionEvent) 我创建自己的向导 - 它运作良好。

public class NewCssWizardHandler extends WizardHandler
{
   @Override
   protected void executeHandler(ExecutionEvent event)
   {
     try
     {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        WizardDialog wizardDialog = new WizardDialog(window.getShell(), new NewCSSWizard());
        wizardDialog.open();
      }
      catch (ExecutionException e)
      {
        e.printStackTrace();
      }        
   }

   @Override
   protected String getWizardIdParameterId()
   {
      return IWorkbenchCommandConstants.FILE_NEW_PARM_WIZARDID;
   }

   @Override
   protected IWizardRegistry getWizardRegistry()
   {
      return PlatformUI.getWorkbench().getNewWizardRegistry();
   }
}

堆栈跟踪:

org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
    at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:831)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:724)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:708)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:647)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
    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:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.NullPointerException
    at org.eclipse.ui.ide.IDE.computeSelectedResources(IDE.java:1480)
    at org.eclipse.wst.css.ui.internal.wizard.NewCSSWizard.addPages(NewCSSWizard.java:48)
    at org.eclipse.jface.wizard.WizardDialog.createContents(WizardDialog.java:605)
    at org.eclipse.jface.window.Window.create(Window.java:431)
    at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
    at org.eclipse.jface.window.Window.open(Window.java:790)
    at com.sdad.sdk.ui.actions.NewCssWizardHandler.executeHandler(NewCssWizardHandler.java:27)
    at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:279)
    at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
    at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
4

2 回答 2

0

看起来您将空参数传递给computeSelectedResources. 只需在调用该方法之前进行空检查。我假设您正在处理的代码是NewCSSWizard.java.

于 2013-05-31T17:50:03.843 回答
-2
public class NewFileHandler extends AbstractHandler implements IHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {

        IWorkbenchWindow window = HandlerUtil
                .getActiveWorkbenchWindowChecked(event);
        System.out.println("window ok");

        NewFileWizard nfw = new NewFileWizard();

        nfw.init(PlatformUI.getWorkbench(), new StructuredSelection());
        WizardDialog dialog = new WizardDialog(window.getShell(), nfw);
        System.out.println("new WizardDialog");
        dialog.open();
        System.out.println("dialog open");
        return null;
    }

}
于 2014-07-09T11:28:48.813 回答