views:

444

answers:

2
 //obtain the active page
 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

returns Exception in thread "Thread-3" java.lang.NullPointerExceptionµ. What shall i do?

A: 

Resolve the exception by finding out what is null. Good luck.

Noon Silk
+2  A: 

Add some null checks, it is possible for the workbench to not have an active window, not it is also possible for PlatformUI.getWorkbench to throw an IllegalStateException if the workbench is not yet started (e.g createAndRunWorkbench() has not yet been called).

IWorkbenchWindow window = PlatformUI.getWorkbench().getInstance()
    .getActiveWorkbenchWindow();

if(workbenchWindow != null) {
     IWorkbenchPage page = window .getActivePage();
}
Rich Seller