Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Getting nullpointerexception while fetching current runtime project
Getting nullpointerexception while fetching current runtime project [message #655876] Wed, 23 February 2011 00:21 Go to next message
Ani  is currently offline Ani Friend
Messages: 37
Registered: November 2010
Member
hi,

I've a plugin which is running on the workspace. in the runtime
environment, i created a project "test" and a file inside this
project. I need to get this project path and name to create some files inside it at runtime.

If i try ResourcesPlugin.getWorkspace().getRoot().getProjects()[0]
it returns me path to the test folder.

But here i dont know which index of the projects to take.
so now when i try to get the project with
ResourcesPlugin.getWorkspace().getRoot().getProject()
it returns me null.

if i select the project, then i'm able to get the project from the
selectionservice and iresource like below.

IResource extractSelection(ISelection sel) {
if (!(sel instanceof IStructuredSelection))
return null;
IStructuredSelection ss = (IStructuredSelection) sel;
Object element = ss.getFirstElement();
if (element instanceof IResource)
return (IResource) element;
if (!(element instanceof IAdaptable))
return null;
IAdaptable adaptable = (IAdaptable)element;
Object adapter = adaptable.getAdapter(IResource.class);
return (IResource) adapter;
}
System.out.println(resource.getProject());

But i will not have the selection available always.

Can anyone kindly tell me how to get the current project from the runtime environment !

Thanks,
Re: Getting nullpointerexception while fetching current runtime project [message #655891 is a reply to message #655876] Wed, 23 February 2011 04:44 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 23/02/11 5:51 AM, Ani wrote:
> hi,
>
> I've a plugin which is running on the workspace. in the runtime
> environment, i created a project "test" and a file inside this
> project. I need to get this project path and name to create some files
> inside it at runtime.
>

You can get the project if you know its
name:ResourcesPlugin.getWorkspace().getRoot().getProject(<name of the
project>)

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Getting nullpointerexception while fetching current runtime project [message #656068 is a reply to message #655891] Thu, 24 February 2011 01:40 Go to previous message
Ani  is currently offline Ani Friend
Messages: 37
Registered: November 2010
Member
Hi, Thanks for the response.
But there i don't have the name of the project.

as a work around, i tried the below approach to get the container of the active editor and then from there navigating to a relative path.

(EditorPart)getActiveWorkbench().getActivePage().getActiveEd itor().getEditorInput()).getFile().getParent()

i think this is not an optimum approach, please let me know if there are alternates.

Thanks,
Previous Topic:Force uninstall of legacy feature
Next Topic:Enforcing feature dependencies in Update site
Goto Forum:
  


Current Time: Sat Aug 15 17:44:52 GMT 2020

Powered by FUDForum. Page generated in 0.01430 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top