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);
0
1 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 the plugin.xml file. It should be done with dollar character:

<projectService serviceImplementation="factory.DebuggerFactory$ProjectService"/>

BTW

  1. A more convenient way of getting project service is simple: project.getService(ProjectService.class).
  2. You don't need the serviceInterface attribute as you don't have any interface.
0

Please sign in to leave a comment.