定位过程
一、日志
02-23 16:10:56.933 4876 4876 E AndroidRuntime: FATAL EXCEPTION: main
02-23 16:10:56.933 4876 4876 E AndroidRuntime: Process: com.android.settings, PID: 4876
02-23 16:10:56.933 4876 4876 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.SubSettings}: android.content.res.Resources$NotFoundException: Resource ID #0x0
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.ActivityThread.-wrap12(ActivityThread.java)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6121)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.content.res.Resources.loadXmlResourceParser(Resources.java:2101)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.content.res.Resources.getXml(Resources.java:1164)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:115)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.support.v7.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:127)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.support.v14.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:440)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.settings.SettingsPreferenceFragment.addPreferencesFromResource(SettingsPreferenceFragment.java:144)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.settings.SecuritySettings$SecuritySubSettings.createPreferenceHierarchy(SecuritySettings.java:1084)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.settings.SecuritySettings$SecuritySubSettings.onCreate(SecuritySettings.java:1046)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.Fragment.performCreate(Fragment.java:2336)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:949)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.BackStackRecord.setLastIn(BackStackRecord.java:860)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.BackStackRecord.calculateFragments(BackStackRecord.java:900)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.BackStackRecord.run(BackStackRecord.java:728)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:563)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.settings.SettingsActivity.switchToFragment(SettingsActivity.java:1144)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.settings.SettingsActivity.onCreate(SettingsActivity.java:669)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6723)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
02-23 16:10:56.933 4876 4876 E AndroidRuntime: ... 9 more
02-23 16:10:56.935 1394 2357 I am_crash: [4876,0,com.android.settings,952647237,android.content.res.Resources$NotFoundException,Resource ID #0x0,ResourcesImpl.java,190]
二、
追踪日志 ,发现
02-23 16:10:56.933 4876 4876 E AndroidRuntime: at com.android.settings.SecuritySettings$SecuritySubSettings.onCreate(SecuritySettings.java:1046)
这块为空
三、查看代码
private void createPreferenceHierarchy() {
PreferenceScreen root = getPreferenceScreen();
if (root != null) {
root.removeAll();
}
root = null;
final int resid = getResIdForLockUnlockSubScreen(getActivity(),
new LockPatternUtils(getContext()),
ManagedLockPasswordProvider.get(getContext(), MY_USER_ID));
1084 addPreferencesFromResource(resid); 这个为空了
// lock after preference
mLockAfter = (TimeoutListPreference) findPreference(KEY_LOCK_AFTER_TIMEOUT);
if (mLockAfter != null) {
setupLockAfterPreference();
updateLockAfterPreferenceSummary();
}
// visible pattern
mVisiblePattern = (SwitchPreference) findPreference(KEY_VISIBLE_PATTERN);
四、解决方案,
一、增加int 类型的非空判断处理
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 4876541..0ab2fb9 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -1083,6 +1083,12 @@
final int resid = getResIdForLockUnlockSubScreen(getActivity(),
new LockPatternUtils(getContext()),
ManagedLockPasswordProvider.get(getContext(), MY_USER_ID));
+
+ if (resid == 0) {
+ finish();
+ return;
+ }
+
addPreferencesFromResource(resid);
// lock after preference
二、增加异常捕获
try {
addPreferencesFromResource(resid);
} catch (Exception e) {
Log.e(TAG, "getResIdForLockUnlockSubScreen resid = "+resid);
}
五、问题解决。