8

在我将 jre 升级到 7u40 之前,我的应用程序运行良好。当我的应用程序正在初始化时,它正在执行 Logger.getLogger("ClassName"),并且我收到以下异常。

java.lang.ExceptionInInitializerError
    at java.util.logging.Logger.demandLogger(Unknown Source)
    at java.util.logging.Logger.getLogger(Unknown Source)
    at com.company.Application.Applet.<clinit>(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javaws.Launcher.executeApplication(Unknown Source)
    at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
    at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at com.sun.javaws.Launcher.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.NullPointerException
    at java.util.logging.Logger.setParent(Unknown Source)
    at java.util.logging.LogManager$6.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.logging.LogManager.doSetParent(Unknown Source)
    at java.util.logging.LogManager.access$1100(Unknown Source)
    at java.util.logging.LogManager$LogNode.walkAndSetParent(Unknown Source)
    at java.util.logging.LogManager$LoggerContext.addLocalLogger(Unknown Source)
    at java.util.logging.LogManager$LoggerContext.addLocalLogger(Unknown Source)
    at java.util.logging.LogManager.addLogger(Unknown Source)
    at java.util.logging.LogManager$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.logging.LogManager.<clinit>(Unknown Source)

例外来自这一行:

private static Logger logger = Logger.getLogger(Applet.class.getName());

可能是因为修复http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8017174的任何副作用?

一种解决方法是打开 java 控制中心并启用日志记录。这是一个问题,因为默认情况下未选中“启用日志记录”。如果我选择“启用日志记录”,应用程序将正常启动。

4

2 回答 2

1

这个问题似乎在 java7 update 45 中得到修复。

于 2013-10-22T05:47:04.107 回答
0

尝试将java.util.logging.*您的应用程序打包到 JAR 中,并确保它位于类路径中。这样它总是可用的。另外,您的 logging.properties 是什么样的?

于 2013-10-22T03:49:42.583 回答