ServiceManager.getService for ProjectService creation gives null value
Answered
I have written a ProjectService class as below:
public static class ProjectService {
private HorBugTable bugsTable;
public HorBugTable getHoBugTable() {
return bugsTable;
}
void setHorBugTable(HorBugTable bugsTable) {
this.bugsTable = bugsTable;
}
}
I registered the class in XML the following way:
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="Video" secondary="false" icon="/icons/video6x16.svg" anchor="bottom"
factoryClass="factory.DebuggerFactory"/>
<projectService serviceInterface="factory.DebuggerFactory.ProjectService"
serviceImplementation="factory.DebuggerFactory.ProjectService" />
</extensions>
I get a null pointer exception when I instantiate this class with the following (I also see getService is depreciated but ComponentManager.getServices() shows compile error.) What am I doing wrong?
ProjectService projectService = ServiceManager.getService(project, ProjectService.class);
projectService.setHorBugTable(bugsTable);
Please sign in to leave a comment.
Hi,
Why do you have the
static
modifier in your class header? It seems that you have a nested class, and you reference it wrongly in theplugin.xml
file. It should be done with dollar character:BTW
project.getService(ProjectService.class)
.serviceInterface
attribute as you don't have any interface.