0
votes

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!

1
I think you need to provide the a reduced enclosing class, imports, etc - efekctive
Apologies... I appreciate you trying to help, but I can't seem to fix this. You were right about the resourceSetProvider being null, so something is failing in the injection... I failed to mention this block of code I showed is inside a class, if relevant. - sentient_6
Well, I managed to solve it by removing the injection altogether and instancing an IResourceSetProvider manually. IResourceSetProvider rs1 = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(uri).get(IResourceSetProvider.class); - sentient_6
I am glad you worked it out. If it is not too much could accept the answer? - efekctive
Sure thing! Thanks for the help! :-) - sentient_6

1 Answers

0
votes

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