简体   繁体   English

使用log4J-2.0-beta时的NPE

[英]NPE when using log4J-2.0-beta

I am checking out log4j2 via the overview documentation and I am getting the following exception when trying to setup the log4j2 logger: 我通过概述文档检查log4j2,并在尝试设置log4j2记录器时收到以下异常:

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:129)
    at HelloWorld.<clinit>(HelloWorld.java:5)

My test program is taken from the overview site: 我的测试程序来自概述站点:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class HelloWorld {
    private static Logger logger = LogManager.getLogger("HelloWorld");
    public static void main(String[] args) {
        logger.info("Hello, World!");
    }
}

I added all the provided jar files from the binary distribution to my build path. 我将所有提供的jar文件从二进制分发添加到我的构建路径。

What am I missing? 我错过了什么?

Simply don't! 根本就不要! Use Logback instead of Log4J! 使用Logback而不是Log4J!

For anyone who stumble across this in the future: 对于任何在未来偶然遇到这种情况的人:

JAR log4j-core-2.0-beta2-sources is the cause of the error. JAR log4j-core-2.0-beta2-sources是导致错误的原因。 If you remove this JAR from your build path you can build properly. 如果从构建路径中删除此JAR,则可以正确构建。

I opened up a JIRA ticket on the ASF tracker located at https://issues.apache.org/jira/browse/LOG4J2-118 regarding this issue. 关于此问题,我在位于https://issues.apache.org/jira/browse/LOG4J2-118的ASF跟踪器上打开了一张JIRA票。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用log4j-api-2.0.1.jar和log4j-core-2.0.1.jar替换log4j-api-2.0-beta9.jar,log4j-core-2.0-beta9不起作用 - Replacing log4j-api-2.0-beta9.jar,log4j-core-2.0-beta9 with log4j-api-2.0.1.jar and log4j-core-2.0.1.jar not working NPE与Perf4j和Log4j - NPE with Perf4j and Log4j 在osx下的独立java应用程序中使用log4j 2.0时,log4j2.xml中的日期变量无法解析 - date variable not resolve in log4j2.xml when using log4j 2.0 in standalone java app under osx 在跟踪级别将SUL4J与JUL一起使用时,NPE - NPE when using JUL with SLF4J at trace level Log4j Logger.getLogger(Class)在使用jMockit和Cobertura运行时抛出NPE - Log4j Logger.getLogger(Class) throws NPE when running with jMockit and Cobertura 使用CamelBlueprintTestSupport时的NPE - NPE when using CamelBlueprintTestSupport NPE将数据保存到neo4j时 - NPE When saving data to neo4j Log4j 2.0-日志文件中没有日志-使用log4j2.xml尝试同一类中的多个日志记录器 - Log4j 2.0 - No Logs appearing in the Log Files - Trying Multiple Loggers in the same Class using log4j2.xml Log4j2使用spring时找不到? - Log4j2 Not found when using spring? 以编程方式查找log4j2(beta9)日志文件名 - Programmatically find the log4j2 (beta9) log filename
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM