0

I am trying to get an icon from a package name. The package name is getting passed to me through a socket. I am getting the package name and trying to use it to get the icon, but it is throwing an exception. I never get the print statement for the icon. Any ideas why?

           try  {

              Socket socket = new Socket("192.170.10.15", 5050);


              DataInputStream DIS = new DataInputStream(socket.getInputStream());


              String packagename = DIS.readUTF();
              System.out.println("package name" + packagename);


              Drawable icon = getPackageManager().getApplicationIcon(packagename);
              System.out.println("icon" + icon);


              socket.close();


           } catch (Exception e) {
              System.out.println("Did not receive string");
           }

The exception that is getting thrown is this: my exception now, when I want the icon for "Iso Mounter" app, is:

Exception is android.content.pm.PackageManager$NameNotFoundException: com.iso.mounter –
Natalie
  • 315
  • 5
  • 18
  • Typically when exceptions are thrown, they're thrown to tell you what the problem is. For us to help debug this problem we'll need to know what exception is being thrown. – mcraenich Apr 26 '16 at 23:51
  • @CanadianCoder The exception being thrown is just the "catch" statement I have, which I set to print "Did not receive string". And this gets catch gets printed before "icon" prints, so I know the issue is with Drawable icon. Maybe there is a better way I can debug to see what the issue is? – Natalie Apr 27 '16 at 02:58
  • Try to print the exception like this : catch (Exception e) { System.out.println("Exception is "+e.toString()); } – WannaBeGeek Apr 27 '16 at 03:53
  • @WannaBeGeek Thank you! That is very helpful. my exception now, when I want the icon for "Iso Mounter" app, is: Exception is android.content.pm.PackageManager$NameNotFoundException: com.iso.mounter – Natalie Apr 27 '16 at 23:56
  • Do you have package named "com.iso.mounter" in your app ? – WannaBeGeek Apr 28 '16 at 03:49
  • @WannaBeGeek I realized that I don't have that package name in my app... So I will work on that. – Natalie Apr 28 '16 at 18:52

0 Answers0