java.util.logging.Logger and log4j

后端 未结 3 1351
礼貌的吻别
礼貌的吻别 2021-01-14 08:51

I am trying to compile the code from here: http://www.brackeen.com/javagamebook/#download (Chapter 6) and am having trouble. I don\'t understand how java.util.logging.

相关标签:
3条回答
  • 2021-01-14 09:06

    The import of java.util.logging.Logger in your class seems to cause the problem (the compiler tries to compile against that one, altough it seems the intention was to use the log4j Logger class).

    Try to remove the java.util.logging.Logger from the imports and recompile.

    EDIT: Well, I just checked the original GameServer.java from the ZIP file linked in the page linked in the question. it does NOT contain any import of java.util.logging.Logger there. My guess is thus:

    • You do not have log4j on the classpath of your project
    • You or your IDE tried to somehow organize the imports automatically. This ended up adding java.util.logging.Logger to the imports because no other class of that name was found in project's classpath.

    So, add log4j to the classpath first, then remove the java.util.logging.Logger from the imports.

    0 讨论(0)
  • 2021-01-14 09:10

    Could you please format your code ? Ti would be much more readable ...

    You are trying to call the error(String, String) method on an instance of java.util.logger.Logger. There is no such method. You should use Logger.log(Level.SEVERE, "mesage") instead, or use an instance of a log4J Logger. Check the import section of your source file ...

    0 讨论(0)
  • 2021-01-14 09:27

    java.util.logging.Logger does not have a warn() method (although it does have a warning() method).

    However, org.apache.log4j.Logger does indeed have a method named warn().

    Are you sure you are importing the correct classes?

    0 讨论(0)
提交回复
热议问题