我正在拨打以下电话:
Intent launchIntent = context.getPackageManager()
.getLaunchIntentForPackage(packageName);
使用以下stackTrace与NPE崩溃:
java.lang.NullPointerException at android.app.Instrumentation.execStartActivity(Instrumentation.java:1423) 在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) 在utils.AppsLauncher.void launchAppIfInstalledOtherwiseMarket(android.app.Activity,java.lang.String中,utils.AppReportingParams)(的SourceFile:73) 在utils.AppsLauncher.void launchAppIfInstalledOtherwiseMarket(android.app.Activity,java.lang.String中)(的SourceFile:51) 在adapters.BaseGamesListAdapter.void launchAppIfInstalledOtherwiseMarket(java.lang.String中)(的SourceFile:119) 在 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) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)at dalvik.system.NativeStart.main(原生方法)
我假设getLaunchIntentForPackage(packageName)返回null Intent。我无法弄清楚GREPcode为什么会返回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)
重要的是要注意包确实存在并安装在设备上。
答案 0 :(得分:-3)
context
或context.getPackageManager()
为空。