gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:32 30 4
gpt4 key购买 nike

我正在尝试在 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 对象包含与示例应用程序中显示的相同的路由),但它似乎在尝试创建允许用户选择路由的对话框 (MediaRouter.ShowDialog()) 时崩溃。我找不到此错误的修复方法,因为我无权访问此类似乎崩溃的源代码 (MediaRouteChooserDialog)。我什至尝试实现自定义对话框工厂 ( https://developer.android.com/reference/android/support/v7/app/MediaRouteDialogFactory.html ) 和自定义点击监听器,但这些似乎都不起作用,当我点击按钮时它仍然抛出错误。

有什么想法吗?

最佳答案

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

关于c# - Xamarin - MediaRouteButton ShowDialog() 方法抛出 NullPointerException (Xamarin.Android.Support.v7.MediaRouter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38385512/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com