我正在运行StrictMode.enableDefaults()
来清理我的代码,并且我有一行代码将ZoneId
设置为单行代码,每10次违反StrictMode
的时间大约为195ms 。该行上方的Log.d
语句在 Logcat 中仅显示一次。如果使用ZoneId.of(tz.getID())
,则会收到相同的错误。
这是怎么回事?我检查了ZoneId
的来源,原因对我来说并不明显。这是来自ZoneId
的解析输入吗?日志时间仅从 16:46:09.079 到 16:46:09.080 ,否则10条堆栈轨迹看起来相同。
我真的失去了大约195ms x 10的错误吗?或者这是某种错误?谢谢
例程出现错误:
if (lastUpdateZoneOffset.equals(utcOffset)) {
// last update offset is zero, so add back time from observation station time zone
Log.d(TAG, "tz.getID()");
//ZoneId observationStationZoneId = ZoneId.of(tz.getID());
ZoneId observationStationZoneId = ZoneId.of("America/Denver"); **<---Error Here**
ZonedDateTime zdt = offsetDateTime.atZoneSameInstant(observationStationZoneId);
// format to 14 Apr 4:16 PM Note: the "a" pattern only allows upper case for AM/PM
lastUpdate = zdt.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
} else {
lastUpdate = offsetDateTime.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
}
典型堆栈跟踪:
01-01 16:46:09.079 24614-24614 D/StrictMode: StrictMode policy violation; ~duration=196 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=31 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1137)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:182)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:117)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:158)
at java.util.zip.ZipFile.<init>(ZipFile.java:119)
at dalvik.system.DexPathList$Element.maybeInit(DexPathList.java:431)
at dalvik.system.DexPathList$Element.findResource(DexPathList.java:445)
at dalvik.system.DexPathList.findResources(DexPathList.java:361)
at dalvik.system.BaseDexClassLoader.findResources(BaseDexClassLoader.java:72)
at java.lang.ClassLoader.getResources(ClassLoader.java:425)
at java.util.ServiceLoader.internalLoad(ServiceLoader.java:129)
at java.util.ServiceLoader.reload(ServiceLoader.java:93)
at java.util.ServiceLoader.<init>(ServiceLoader.java:86)
at java.util.ServiceLoader.load(ServiceLoader.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer$ServiceLoaderZoneRulesInitializer.initializeProviders(ZoneRulesInitializer.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer.initialize(ZoneRulesInitializer.java:89)
at org.threeten.bp.zone.ZoneRulesProvider.<clinit>(ZoneRulesProvider.java:82)
at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:121)
at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
at org.threeten.bp.ZoneId.of(ZoneId.java:358)
at com.drme.weatherNoaa.CurrentConditionsFragment.getDisplayLastUpdate(CurrentConditionsFragment.java:674)
at com.drme.weatherNoaa.CurrentConditionsFragment.updateCurrentConditionsUi(CurrentConditionsFragment.java:543)
at com.drme.weatherNoaa.DataManager$1.handleMessage(DataManager.java:201)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)