Java – my Android application crashes, even if I’m catching the exception that caused it to crash
•
Java
This is my code:
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; }
The broken line is:
PackageInfo pi = getPackageManager().getPackageInfo(aname,0);
Because I'm catching mistakes, it doesn't make any sense I hope someone can tell me what I did wrong, or it's some kind of Android error This is what the log shows:
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)
Solution
You may want to ensure that your package name string is formatted correctly, and you may not be able to catch the correct exception
Note that the exception is packagemanager NameNotFoundException
http://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码