我正在处理的应用使用通用媒体播放器或Nex播放器播放其视频文件。我的任务是让它使用Google ExoPlayer,而我一直在努力实施。但是,由于在作为exoplayer2包的一部分的Util类中发生的NullPointerException,我无法初始化ExoPlayer类。
我的代码中已经实现了以下方法,并用于初始化本机播放器和nexplayer。
private void onLaunchStreamingSuccess() {
final Context context = MediaDetailsStageButtons.this.getContext();
final Intent intent = new Intent(context, ExoStreamingPlaybackScreen.class);
intent.putExtra( AbstractMediaDetailsScreen.EXTRA_MEDIA_ID, MediaDetailsStageButtons.this.mMedia.getID() );
context.startActivity(intent);
}
调用startActivity后,应用程序崩溃并显示以下日志语句
11-09 11:45:10.163 27482 27482 E QewErrorReporter: Entered uncaughtException [caught Exception: Unable to instantiate activity ComponentInfo{com.directv.application.android.go.production/com.morega.qew.ui.streaming.ExoStreamingPlaybackScreen}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference]
11-09 11:45:10.163 27482 27482 E QewErrorReporter: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.directv.application.android.go.production/com.morega.qew.ui.streaming.ExoStreamingPlaybackScreen}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3096)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.app.ActivityThread.access$1100(ActivityThread.java:223)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1797)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.os.Handler.dispatchMessage(Handler.java:102)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.os.Looper.loop(Looper.java:158)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.app.ActivityThread.main(ActivityThread.java:7231)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at java.lang.reflect.Method.invoke(Native Method)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:97)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at com.google.android.exoplayer2.util.Util.getUserAgent(Util.java:676)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at com.morega.qew.ui.streaming.ExoStreamingPlaybackScreen.<init>(ExoStreamingPlaybackScreen.java:88)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at java.lang.Class.newInstance(Native Method)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.app.Instrumentation.newActivity(Instrumentation.java:1096)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
11-09 11:45:10.163 27482 27482 E QewErrorReporter: ... 9 more
进入Util类,方法&#39; getUserAgent&#39;是问题发生的地方,特别是在try块的第二行。
public static String getUserAgent(Context context, String applicationName) {
String versionName;
try {
String packageName = context.getPackageName();
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
versionName = info.versionName;
} catch (NameNotFoundException e) {
versionName = "?";
}
return applicationName + "/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE
+ ") " + "ExoPlayerLib/" + ExoPlayerLibraryInfo.VERSION;}
这可能只是我对Android的经验不足,这就是我无法解决这个问题的原因,但我希望能帮助我解决这个问题。
答案 0 :(得分:0)
line 88
ExoStreamingPlaybackScreen.java
正在进行哪些通话?看起来这就是发生崩溃的地方。
您传递的Context
可能是null
。