gpt4 book ai didi

java - Log4J 出现 "cannot find symbol"错误,即使我正在遵循教程

转载 作者:行者123 更新时间:2023-12-01 14:37:28 26 4
gpt4 key购买 nike

我收到以下错误:

1 error found:
File: C:\Users\adem\Desktop\various_topics\JavaProjects\log4jExample.java [line: 15]
Error: cannot find symbol
symbol: method getLogger(java.lang.String)
location: interface org.apache.logging.log4j.Logger

这是我的代码,基于此 tutorial :

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

public class log4jExample{

/* Get actual class name to be printed on */
static Logger log = Logger.getLogger(log4jExample.class.getName()); //.getName()
public static void main(String[] args)
throws IOException,SQLException{

log.debug("Hello this is an debug message");
log.info("Hello this is an info message");
}
}

谢谢!

最佳答案

您需要导入:

import org.apache.log4j.Logger;

如果您使用 Maven,则可以使用以下依赖项:

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
</dependency>

关于java - Log4J 出现 "cannot find symbol"错误,即使我正在遵循教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16349182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com