title: Android getLaunchIntentForPackage returns null
body: <p>I am making the following call:         </p>
  
  <pre><code>Intent launchIntent = context.getPackageManager()
                                   .getLaunchIntentForPackage(packageName);
  </code></pre>
  
  <p>It crashes with NPE with the following stackTrace:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException at
    android.app.Instrumentation.execStartActivity(Instrumentation.java:1423)
    at android.app.Activity.startActivityForResult(Activity.java:3584) at
    android.app.Activity.startActivityForResult(Activity.java:3545) at
    android.support.v4.app.FragmentActivity.void
    startActivityForResult(android.content.Intent,int)(SourceFile:817) at
    android.app.Activity.startActivity(Activity.java:3787) at
    android.app.Activity.startActivity(Activity.java:3755) at
    utils.AppsLauncher.voidlaunchApp(android.content.Context,java.lang.String)(SourceFile:100)
    at utils.AppsLauncher.void
    launchAppIfInstalledOtherwiseMarket(android.app.Activity,java.lang.String,utils.AppReportingParams)(SourceFile:73)
    at utils.AppsLauncher.void
    launchAppIfInstalledOtherwiseMarket(android.app.Activity,java.lang.String)(SourceFile:51)
    at adapters.BaseGamesListAdapter.void
    launchAppIfInstalledOtherwiseMarket(java.lang.String)(SourceFile:119)
    at
    adapters.UserGamesAdapter$UserGameUIHolder$1.void
    onClick(android.view.View)(SourceFile:198) at
    android.view.View.performClick(View.java:4658) at
    android.view.View$PerformClick.run(View.java:19461) at
    android.os.Handler.handleCallback(Handler.java:733) at
    android.os.Handler.dispatchMessage(Handler.java:95) at
    android.os.Looper.loop(Looper.java:146) at
    android.app.ActivityThread.main(ActivityThread.java:5692) at
    java.lang.reflect.Method.invokeNative(Native Method) at
    java.lang.reflect.Method.invoke(Method.java:515) at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) at
    dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>
  
  <p>I assume that getLaunchIntentForPackage(packageName) returns a null Intent. I can't figure out in GREPcode why exactly it returns null: (<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-0/android/app/ApplicationPackageManager.java#ApplicationPackageManager.getLaunchIntentForPackage%28java.lang.String%29" rel="nofollow">http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-0/android/app/ApplicationPackageManager.java#ApplicationPackageManager.getLaunchIntentForPackage%28java.lang.String%29</a>)</p>
  
  <p>It is important to note that the package does indeed exist and is installed on the device.</p>