java - MissingResourceException : Can't find bundle for base name sun. util.logging.resources.logging,语言环境 en_US

标签 java android okhttp cookiemanager

我得到了,

Caused by java.lang.InternalError: java.util.MissingResourceException: Can't find bundle for base name sun.util.logging.resources.logging, locale en_US 

在我的来自 firebase 崩溃报告的应用程序中。

其他细节

Manufacturer: HTC
Model: HTC 10 
Android API: 24 

这是堆栈跟踪

java.util.logging.Logger$1.run (Logger.java:1385)
java.util.logging.Logger$1.run (Logger.java:1379)
java.security.AccessController.doPrivileged (AccessController.java:41)
java.util.logging.Logger.findSystemResourceBundle (Logger.java:1378)
java.util.logging.Logger.findResourceBundle (Logger.java:1425)
java.util.logging.Logger.setupResourceInfo (Logger.java:1523)
java.util.logging.Logger.<init> (Logger.java:266)
java.util.logging.Logger.<init> (Logger.java:261)
java.util.logging.LogManager$SystemLoggerContext.demandLogger (LogManager.java:734)
java.util.logging.LogManager.demandSystemLogger (LogManager.java:399)
java.util.logging.Logger.getPlatformLogger (Logger.java:474)
java.util.logging.LoggingProxyImpl.getLogger (LoggingProxyImpl.java:41)
sun.util.logging.LoggingSupport.getLogger (LoggingSupport.java:100)
sun.util.logging.PlatformLogger$JavaLoggerProxy.<init> (PlatformLogger.java:636)
sun.util.logging.PlatformLogger$JavaLoggerProxy.<init> (PlatformLogger.java:631)
sun.util.logging.PlatformLogger.<init> (PlatformLogger.java:246)
sun.util.logging.PlatformLogger.getLogger (PlatformLogger.java:205)
java.net.CookieManager.put (CookieManager.java:262)
okhttp3.JavaNetCookieJar.saveFromResponse (JavaNetCookieJar.java:47)
okhttp3.internal.http.HttpHeaders.receiveHeaders (HttpHeaders.java:182)
okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java:95)
okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92)
okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:120)
okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92)
okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:67)
okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:185)
okhttp3.RealCall.execute (RealCall.java:69)

这里是相关的Logger代码

private static ResourceBundle findSystemResourceBundle(final Locale var0) {
        return (ResourceBundle)AccessController.doPrivileged(new PrivilegedAction() {
            public ResourceBundle run() {
                try {
                    return ResourceBundle.getBundle("sun.util.logging.resources.logging", var0, ClassLoader.getSystemClassLoader());
                } catch (MissingResourceException var2) {
                    throw new InternalError(var2.toString());
                }
            }
        });
    }

我也收到了语言环境 en_AU 的崩溃报告。

由于崩溃的代码不是我控制的,我该如何防止崩溃?

最佳答案

分析:

MissingResourceException: Can't find bundle for base name sun.util.logging.resources.logging, locale en_US

系统生成候选包名称

sun/util/logging/resources/logging_en_US
sun/util/logging/resources/logging_en
sun/util/logging/resources/logging

对于每个候选包名称,它会尝试加载一个资源包:

First, it attempts to load a class using the generated class name.

If such a class can be found and loaded using the specified class loader, is assignment compatible with ResourceBundle, is accessible from ResourceBundle, and can be instantiated, getBundle creates a new instance of this class and uses it as the result resource bundle.

Otherwise, getBundle attempts to locate a property resource file using the generated properties file name.

It generates a path name from the candidate bundle name by replacing all "." characters with "/" and appending the string ".properties". It attempts to find a "resource" with this name using java.lang.ClassLoader.getResource(java.lang.String). (Note that a "resource" in the sense of getResource has nothing to do with the contents of a resource bundle, it is just a container of data, such as a file.) If it finds a "resource", it attempts to create a new PropertyResourceBundle instance from its contents. If successful, this instance becomes the result resource bundle.

看得更详细here如何解析资源。

由于系统正在类路径中以降序查找任何这些文件(通常没有 _en*.properties)

sun/util/logging/resources/logging_en_US.properties
sun/util/logging/resources/logging_en.properties
sun/util/logging/resources/logging.properties

添加这样的 file 将是一种解决方法(或上面提到的类)到您的应用程序。 属性文件的内容类似于 this :

# Localizations for Level names.  For the US locale
# these are the same as the non-localized level name.

# The following ALL CAPS words should be translated.
ALL=All
# The following ALL CAPS words should be translated.
SEVERE=Severe
# The following ALL CAPS words should be translated.
WARNING=Warning
# The following ALL CAPS words should be translated.
INFO=Info
# The following ALL CAPS words should be translated.
CONFIG= Config
# The following ALL CAPS words should be translated.
FINE=Fine
# The following ALL CAPS words should be translated.
FINER=Finer
# The following ALL CAPS words should be translated.
FINEST=Finest
# The following ALL CAPS words should be translated.
OFF=Off

关于java - MissingResourceException : Can't find bundle for base name sun. util.logging.resources.logging,语言环境 en_US,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44756268/

相关文章:

android - 防止 OkHttp/Retrofit 绕过代理

java - 循环停止执行时迭代器的值

java - 如何在 LibGDX 项目中显示插屏广告?

java - DocumentBuilderFactory 在 Java 5+ 中是线程安全的吗?

android - 分享安卓图片查看图片

android - 如何向我的绘图应用程序添加不透明度功能?

android - OkHTTP Websocket : Unexpected end of steam on Connection

android - 单击按钮时异步方法未运行

Java RegEx 用于替换开头和结尾部分与特定模式匹配的字符串

java - 如何在 Android 手机上的应用程序中表示建筑物的内部?