单击Cast Mini Controller时,Android应用程序崩溃

时间:2018-05-29 05:13:40

标签: android gradle android-gradle chromecast

我正在开发一个使用Chromecast的Android应用程序。该视频正在Chromecast上播放,Expanded控制器也正在点击minicontroller应用程序崩溃。这是我的日志

java.lang.NullPointerException: class name is null
        at android.content.ComponentName.<init>(ComponentName.java:63)
        at com.google.android.gms.cast.framework.media.uicontroller.UIMediaController.onLaunchExpandedControllerClicked(Unknown Source)
        at com.google.android.gms.cast.framework.media.uicontroller.zzg.onClick(Unknown Source)
        at android.view.View.performClick(View.java:4473)
        at android.view.View$PerformClick.run(View.java:18780)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5292)
        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:824)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
        at dalvik.system.NativeStart.main(Native Method)

我在XML中添加了以下片段定义

<fragment
        android:id="@+id/castMiniController"
        class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:visibility="gone" />

这是我的依赖

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:26.2.1'
    compile 'com.android.support:mediarouter-v7:v7:26.2.1'
    compile 'com.google.android.gms:play-services-cast-framework:15.0.1'
    compile 'com.googlecode.android-query:android-query:0.25.9'
}

Gradle版本是3.1.2。注意:我遵循标准程序,没有自定义代码。任何建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

如果您尚未在CastOptions类中启动NotificationOptions和CastMediaOptions,则可能出现这种情况。请在您的CastOptions类中添加此行:

NotificationOptions notificationOptions = new NotificationOptions.Builder()
        .setTargetActivityClassName(ExpandedControlsActivity.class.getName())
        .build();
CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
        .setNotificationOptions(notificationOptions)
        .setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
        .build();

请参阅链接https://codelabs.developers.google.com/codelabs/cast-videos-android/#9