0

I'm developing an eclipse plugin , and at some point in my plugin , a jframe is opened , and inside the jframe, there is a button . I have added a mouselistener to the button , and when pressed , I want some code to be added to the editor at caret point . but, I get null pointer exception here:
IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage();

2
  • 1
    Which of those three calls is returning null? getWorkbench()? getActiveWorkbenchWindow()? getActivePage()? Commented Aug 8, 2014 at 15:04
  • getActivePage() is returning null Commented Aug 8, 2014 at 16:32

1 Answer 1

1

It appears you don't have an active page. Maybe your Swing based code is displaying a separate window?

Use IWorkbenchWindow.getPages() to get an array of IWorkbenchPage containing all the pages and look through the pages for the one containing the editor you want.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks! that was the problem! sorry , I am still learning eclipse plugin development !
what is an acivePage exactly? I tried to change the focused window using a robot , but it didn't work.
It is all the things you can see on an Eclipse window, there are multiple pages if you have used several perspectives. Normally you use SWT controls in the page and there will be an active page. Or if a dialog is displayed you schedule work to run after the dialog closes and the page is active again.
I first ran dispose() on the jframe, and then tried to get the active window, and got null pointer. Apparently the page is considered active only after I click on the window...
Sorry, using Swing windows is very unusual with Eclipse plugins, I don't know exactly how this would behave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.