简体   繁体   中英

NullPointerException with IResourceSetProvider?

I have an Xtext project with an issue I can't seem to solve. Consider the following code:

@Inject
IResourceSetProvider resourceSetProvider;

private void function(){
     IProject project = file.getProject();

     URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
     ResourceSet resourceSet = resourceSetProvider.get(project);
     Resource resource = resourceSet.getResource(uri, true);
}

The object "file" is an IFile passed as an argument of this function and is not null, as I am able to access its contents and even print them out as strings, for example. I can also access its IProject field and perform operations on it. However, I'm getting a NullPointerException on the ResourceSet line, namely on the ".get(project)" function. What could cause a NullPointerException to occur at this step, given that said project is definitely not null?

Thanks for the help!

Either project is null or the injection failed and the provider is null. You say variable project is not null. Then injection failed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM