簡體   English   中英

MissingResourceException:無法找到基本名稱sun.util.logging.resources.logging,locale en_US的包

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

我正進入(狀態,

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());
                }
            }
        });
    }

我也有locale en_AU崩潰報告。

由於崩潰代碼不受我控制,我該如何防止此崩潰?

分析:

MissingResourceException:無法找到基本名稱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

對於每個候選包名稱,它會嘗試加載資源包:

首先,它嘗試使用生成的類名加載類。

如果可以使用指定的類加載器找到並加載這樣的類,與ResourceBundle兼容的賦值,可從ResourceBundle訪問,並且可以實例化,則getBundle創建此類的新實例並將其用作結果資源包。

否則,getBundle會嘗試使用生成的屬性文件名來查找屬性資源文件。

它通過替換所有“。”從候選包名稱生成路徑名。 帶有“/”的字符並附加字符串“.properties”。 它嘗試使用java.lang.ClassLoader.getResource(java.lang.String)查找具有此名稱的“資源”。 (請注意,getResource意義上的“資源”與資源包的內容無關,它只是數據的容器,例如文件。)如果找到“資源”,它會嘗試創建來自其內容的新PropertyResourceBundle實例。 如果成功,則此實例將成為結果資源包。

在這里詳細了解如何解決資源問題。

由於系統按降序查找任何這些文件的類路徑(通常沒有_en * .properties)

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

這將是一個解決方法,將這樣的文件 (或上面提到的類)添加到您的應用程序。 屬性文件的內容如下所示

# 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

如果它的工作原理是另一個答案所建議的資源文件是一個更好的選擇,但是如果這沒有成功,我有另一個選擇。 假設您不需要日志記錄,您應該可以像這樣禁用它:

try {
    Class<?> cls = Class.forName("sun.util.logging.PlatformLogger");
    Field field = cls.getDeclaredField("loggingEnabled");
    field.setAccessible(true);
    field.set(null, Boolean.FALSE);
} catch(Exception e) {
    // Failed
}

如果你早點這樣做,PlatformLogger應該構造一個DefaultLoggerProxy而不是JavaLoggerProxy,所以破壞的代碼永遠不會運行。 這是丑陋的,因為它取決於內部實現細節,因為它禁用日志記錄,但它可能適用於您的應用程序?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM