Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LoggerFactory.getLogger cannot be resolved to a type

I setup a basic Java program. I am following this tutorial and have this exact code:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

I have the jars slf4j-api-1.7.5.jar and slf4j-log4j12-1.7.5 jar on my build path. I do not understand what gives, the getLogger method exists in the LoggerFactory class which I can F3 (source code look-up) to. I Googled about this and appear to be the only dope with this problem. Any ideas?

Here is my .classpath for Eclipse:

<xml version="1.0" encoding="UTF-8"?>
<classpath>
   <classpathentry kind="src" path="src"/>
   <classpathentry kind="con" path="org.eclipse.jdit..../>
   <classpathentry kind="lib" path="/home/Desktop/slf4j-api-1.7.5.jar" sourcepath="/home/Desktop/slf4j-api-1.7.5.jar"/>
   <classpathentry kind="lib" path="slf4j-log4j12-1.7.5.jar"/>
   <classpathentry kind="lib" path="log4j-1.2.17.jar"/>
   <classpathentry kind="output" path="bin"/>
</classpath>
like image 808
smuggledPancakes Avatar asked Jun 27 '26 21:06

smuggledPancakes


2 Answers

On the tutorial page you link to, there is the following note:

slf4j-log4j12-1.7.6.jar

Binding for log4j version 1.2, a widely used logging framework. You also need to place log4j.jar on your class path.

Did you include log4j.jar?

like image 53
David Hodgson Avatar answered Jun 29 '26 11:06

David Hodgson


My problem was solved after the inclusion of

slf4j-api-1.7.7.jar and slf4j-simple-1.7.7.jar

on classpath.

like image 25
Alan CN Avatar answered Jun 29 '26 11:06

Alan CN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!