My Android app crashes even though I caught an exception that it says causes a crash

Here 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; } 

Dropdown line:

 PackageInfo pi = getPackageManager().getPackageInfo(aname, 0); 

This makes no sense, as I caught a mistake. Hopefully someone can tell me what I'm doing wrong, or something like an error with Android. This shows the log:

 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) 
+4
source share
2 answers

You might want the string of your package name to be formatted correctly, and you cannot catch the correct exception.

Note that the exception is PackageManager.NameNotFoundException

http://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html

+1
source

You are javax.naming.NameNotFoundException while the exception is thrown by android.content.pm.PackageManager$NameNotFoundException

Try catch (Exception e) and see if this is really your problem.

0
source

Source: https://habr.com/ru/post/1403370/


All Articles