java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.lang.Iterable.iterator()' when starting a notification

▼魔方 西西 提交于 2019-12-04 22:30:56
ApplicationPackageManager.java
private UserInfo getUserIfProfile(int userHandle) {
    List<UserInfo> userProfiles = getUserManager().getProfiles(UserHandle.myUserId());
    for (UserInfo user : userProfiles) {
        if (user.id == userHandle) {
            return user;
        }
    }
    return null;
}

and

public List<UserInfo> getProfiles(int userHandle) {
    try {
        return mService.getProfiles(userHandle, false /* enabledOnly */);
    } catch (RemoteException re) {
        Log.w(TAG, "Could not get user list", re);
        return null;
    }
}

So, if there is something wrong with AIDL request, or user's profile is disabled you will have NPE in ApplicationPackageManager.java code. I think it is impossible to prevent this situation, and I advise you to wrap notification creation in try{}catch block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!