Search code examples
loggingrcpe4

NullPointerException when i want to use the default e4 eclispe logging


I get a NPE when I try to use the default Eclipse logging in a e4 application.

import org.eclipse.e4.core.services.log.Logger;

public abstract class AbstractdUIPlugin extends AbstractUIPlugin {

@Inject
Logger logger;

public void start(BundleContext context) throws Exception {
  super.start(context);
  // logger = LoggingPlugin.getLogger(this);
  logger.info("Plugin[" + getPluginId() + "] started");
}
...

Solution

  • Plugin activators are not injected so you can't use @Inject in them.

    Note that AbstractUIPlugin is a 3.x compatibility mode class, not pure e4.

    You can get the 3.x ILog logging interface in an AbstractUIPlugin activator by calling the getLog() method.