我正在尝试在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$1.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对象包含在示例应用程序中显示的相同路由),但似乎在尝试创建允许用户选择路由的Dialog时崩溃(MediaRouter.ShowDialog())。我无法找到修复此错误,因为我无法访问此类似乎崩溃的源代码(MediaRouteChooserDialog)。我甚至试图实现一个自定义对话框工厂(https://developer.android.com/reference/android/support/v7/app/MediaRouteDialogFactory.html)和一个自定义点击监听器,但这些似乎都不起作用,当我点击按钮时它仍然引发错误。
有什么想法吗?
答案 0 :(得分:1)
我今天也遇到了同样的问题。将组件更新到29.0.0.2已修复它。