|Label provider and icons from workspace [message #557851]
||Thu, 09 September 2010 08:41
| Michal Borek
Registered: August 2010
I've got a problem creating LabelProvider that returs Image chosen by user (from his project workspace).
I've got element Icon with attribute "path".
I need project relative path, so I need to get project. I don't know how, because LabelProvider doesn't have IProject element. When I use
IEditorPart editorPart = WidgetsActivator.getDefault().getWorkbench().getActiveWorkbenchWindow()
IFileEditorInput input = (IFileEditorInput) editorPart.getEditorInput();
IProject activeProject = input.getFile().getProject();
I've got null pointer exception when loading eclipse and there is active tab which using this label provider (but if tab is closed after eclipse start I open this editor, everything's fine).
Could you please tell me how to get project which is parent of file for which this editor is opened ?
|Re: Label provider and icons from workspace [message #558121 is a reply to message #557851]
||Fri, 10 September 2010 09:09
| Martin Klinke
Registered: July 2009
first of all you should check the resources you get from the API for
"null values". For example, if there is no active editor, than
editorPart is null and the access to editorPart.getEditorInput() will
throw the NPE. You need to take these situations into account in your
code. Think about what may happen and read the method documentation for
information about possible null return values.
Powered by FUDForum
. Page generated in 0.01540 seconds