2
votes

I am making the following call:

Intent launchIntent = context.getPackageManager()
                                 .getLaunchIntentForPackage(packageName);

It crashes with NPE with the following stackTrace:

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)

I assume that getLaunchIntentForPackage(packageName) returns a null Intent. I can't figure out in GREPcode why exactly it returns null: (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)

It is important to note that the package does indeed exist and is installed on the device.

1
Did you figure this out? I am facing a similar issue.IgorGanapolsky

1 Answers

-4
votes

The context or context.getPackageManager() is null.