Xamarin - MediaRouteButton ShowDialog() 方法抛出 NullPointerException (Xamarin.Android.Support.v7.MediaRouter)

Xamarin - MediaRouteButton ShowDialog() method throws NullPointerException (Xamarin.Android.Support.v7.MediaRouter)

我正在尝试在 Xamarin Android 中实现 MediaRouteButton 以查找该区域中的 ChromeCast 设备,它使用 android 支持库(NuGeT 包) 我下载了一个示例应用程序(有效,下载 GooglePlayServices - Cast 组件时提供的 CastingCall 项目示例),但是当我尝试将代码传输到它上面时,单击按钮时会抛出错误,如下所示:

[AndroidRuntime] java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
[AndroidRuntime]    at android.support.v7.app.MediaRouteChooserDialog.onCreate(MediaRouteChooserDialog.java:167)
[AndroidRuntime]    at android.app.Dialog.dispatchOnCreate(Dialog.java:465)
[AndroidRuntime]    at android.app.Dialog.show(Dialog.java:288)
[AndroidRuntime]    at android.support.v4.app.DialogFragment.onStart(DialogFragment.java:406)
[AndroidRuntime]    at android.support.v4.app.Fragment.performStart(Fragment.java:1986)
[AndroidRuntime]    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1102)
[AndroidRuntime]    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
[AndroidRuntime]    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
[AndroidRuntime]    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
[AndroidRuntime]    at android.support.v4.app.FragmentManagerImpl.run(FragmentManager.java:517)
[AndroidRuntime]    at android.os.Handler.handleCallback(Handler.java:739)
[AndroidRuntime]    at android.os.Handler.dispatchMessage(Handler.java:95)
[AndroidRuntime]    at android.os.Looper.loop(Looper.java:145)
[AndroidRuntime]    at android.app.ActivityThread.main(ActivityThread.java:6117)
[AndroidRuntime]    at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime]    at java.lang.reflect.Method.invoke(Method.java:372)
[AndroidRuntime]    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
[AndroidRuntime]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

下面是一些代码:

mediaRouteButton = FindViewById<Android.Support.V7.App.MediaRouteButton> (Resource.Id.mediaRouteButton);
mediaRouter = MediaRouter.GetInstance (this);
mediaRouteSelector = new MediaRouteSelector.Builder ()
            .AddControlCategory (MediaControlIntent.CategoryRemotePlayback)
            .Build();
mediaRouteButton.RouteSelector = mediaRouteSelector;

MediaRouteButton 没有变灰,这意味着它正在检测该区域中的正确路由(我调试它只是为了确保,mediaRouter 对象包含与示例应用程序中显示的相同的路由),但是尝试创建允许用户选择路线的对话框 (MediaRouter.ShowDialog()) 时,它似乎崩溃了。我找不到此错误的修复方法,因为我无法访问此 class 的源代码,它似乎正在崩溃 (MediaRouteChooserDialog)。我什至尝试实现一个自定义对话框工厂 (https://developer.android.com/reference/android/support/v7/app/MediaRouteDialogFactory.html) 和一个自定义点击监听器,但这些似乎都不起作用,当我点击按钮时它仍然抛出错误。

有什么想法吗?

我今天突然遇到了同样的问题。将组件更新到 29.0.0.2 修复了它。