Search code examples
androidgradleandroid-gradle-pluginchromecast

android app crashing while clicking on Cast Mini Controller


I'm developing an Android application that uses Chromecast. The video is streaming on Chromecast and Expanded controller is also working however on clicking minicontroller app crashed. Here is my log

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)

I have added following fragment definition in 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" />

And here are my dependencies

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 version is 3.1.2. Note: I am following standard procedure, no custom codes. Any advice would be appreciated.


Solution

  • That might be the case if you have not initiated NotificationOptions and CastMediaOptions inside your CastOptions class. Please add this line inside your class CastOptions :

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

    Please refer to the link https://codelabs.developers.google.com/codelabs/cast-videos-android/#9