I’m new in using the log4j package and I don’t see the error:
This is a very simple and straightforward code sample:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TestLogger {
private static Logger logger;
public static void main(String[] args) {
logger = LogManager.getLogger(TestLogger.class);
logger.info("Hello");
}
}
When I try to compile I get this error:
Exception in thread “main” java.lang.NullPointerException at
org.apache.logging.log4j.LogManager.getLogger(LogManager.java:129) at
my.package.logging.TestLogger.main(TestLogger.java:15)
I am wondering what on earth it’s all supposed to mean …
Could you help here?
You’re most probably missing one of the dependencies. This is easy reproducible if you only include in your classpath the
log4j-api-2.0-beta1.jarfile.If you downloaded the binary distribution, include also the
log4j-core-2.0-beta1.jarin your classpath. If your using Maven, put this in yourpom.xml: