面向NullPointerExceptionWorkbenchPage.ShowView(String viewId)

stackstrace如下。

!MESSAGE从插件调用代码“ org.eclipse.ui.workbench”时出现问题。
!堆栈0

java.lang.NullPointerException
    at org.eclipse.ui.internal.WorkbenchPage.setState(WorkbenchPage.java:4024)
    at org.eclipse.ui.internal.WorkbenchPage.toggleZoom(WorkbenchPage.java:4096)
    at org.eclipse.ui.internal.WorkbenchIntroManager.setIntroStandby(WorkbenchIntroManager.java:201)
    at org.eclipse.ui.internal.WorkbenchPage.checkIntro(WorkbenchPage.java:1202)
    at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1170)
    at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1140)
    at org.eclipse.ui.internal.WorkbenchPage$20.run(WorkbenchPage.java:3925)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3922)
    at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3898)
    at com.rcp.app.foundation.ui.services.PerspectiveChangeListener.perspectiveActivated(PerspectiveChangeListener.java:60)
    at org.eclipse.ui.internal.PerspectiveListenerList$1.run(PerspectiveListenerList.java:74)


我没有得到我确切缺少的东西。谁能帮助我找出我在流程中到底缺少什么。

我写了以下的PerspectiveChangeListner。

    public class PerspectiveChangeListener implements IPerspectiveListener, IPerspectiveListener3
{
/**
  * WindowTitleUpdater Object to update the window title based on selected erspectives.
  */
    private WindowTitleUpdater windowTitleUpdater = null;



/**
     * Constructor.
     * @param windowTitleUpdater
     */
    public PerspectiveChangeListener( WindowTitleUpdater windowTitleUpdater )
    {
        this.windowTitleUpdater = windowTitleUpdater;
    }

   /**
     * (non-Javadoc).
     * @see org.eclipse.ui.IPerspectiveListener#perspectiveActivated(org.eclipse.ui.IWorkbenchPage,
     *      org.eclipse.ui.IPerspectiveDescriptor)
     */


 @Override
    public void perspectiveActivated( IWorkbenchPage page, IPerspectiveDescriptor perspective )
    {
        windowTitleUpdater.updateTitle( false );
        if ( perspective.getId().equals( "com.app.perspective.id" ) )
        {
            try
            {
                page.showView( "com.app.view.id" );
            }
        }
    }

最佳答案

perspectiveActivated侦听器由WorkbenchPage触发,该页面似乎不希望该侦听器在侦听器中调用页面showView方法,如果确实如此,则会感到困惑。

使用Display.asyncExec运行showView调用。这将在WorkbenchPage完成其工作之后运行代码。

08-27 13:00