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.