这是我的代码:
private ArrayList<PInfo> getSelectedPackages() {
ArrayList<PInfo> apps = new ArrayList<PInfo>();
for (String aname : Lock.getAllowedApps()) {
try {
PackageInfo pi = getPackageManager().getPackageInfo(aname, 0);
PInfo newInfo = new PInfo(pi.applicationInfo, getPackageManager());
apps.add(newInfo);
} catch (NameNotFoundException e) {
ErrorReporter.getInstance().handleSilentException(e);
}
}
return apps;
}
崩溃的行是:
PackageInfo pi = getPackageManager().getPackageInfo(aname, 0);
因为我正在捕捉错误,所以没有任何意义。希望有人可以告诉我我做错了什么,或者这是Android的某种错误。这是日志显示的内容:
android.content.pm.PackageManager$NameNotFoundException: com.teachersparadise.dinosaurscoloringbook at android.app.ContextImpl$ApplicationPackageManager.getPackageInfo(ContextImpl.java:1725) at com.nyanapps.lockfortots.free.Home.getSelectedPackages(Home.java:179)
答案 0 :(得分:1)
您可能希望确保您的包名称字符串格式正确,并且您可能无法捕获正确的异常。
请注意,异常是PackageManager.NameNotFoundException
http://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html
答案 1 :(得分:0)
您可能正在捕捉javax.naming.NameNotFoundException
,而引发的异常是android.content.pm.PackageManager$NameNotFoundException
尝试catch (Exception e)
并检查确实是您的问题。