Title says it all.
For some reason my @Inject annotations are not providing my plugin with a logger or a PluginContainer, and this is no bueno.
Code with point of failure:
@Plugin(
id=GeoWorldMain.ID,
name=GeoWorldMain.NAME,
version=GeoWorldMain.VERSION)
public class GeoWorldMain {
public static final String ID = "geoworld";
public static final String NAME = "GeoWorld";
public static final String VERSION = "1.0.2a";
@Inject
private static PluginContainer container;
@Inject
private static Logger logger;
public static PluginContainer GetPluginContainer() {
if(container==null)
logger.debug("isNull"); //**<-- it fails here with a nullPointer Error**
else
logger.debug("isNotNull");
return container;
}
Is the Logger class the correct one? (org.slf4j.Logger)
And the Inject annotation?
And when do you call that (static) method? The plugin has to be constructed…
Upgrading this ‘don’t think’ to a ‘definitely can’t’. Injected fields depend on their container’s identity; statics don’t belong to any object and therefore can’t be deterministically created.
Yep. Consensus was static won’t work with injection… and not only does it make sense, but it fixed the issue. Make your plugin’s main class a singleton folks!