2016-07-14 49 views
2

我試圖在Xamarin Android中實現MediaRouteButton以查找ChromeCast設備,該區域使用Android支持庫(NuGeT包) 我下載了一個示例應用程序(該程序適用於下載GooglePlayServices-Cast組件時提供的CastingCall項目示例),但是當我試圖通過它傳輸代碼時,它會在點擊按鈕時拋出錯誤,如下所示:Xamarin - MediaRouteButton ShowDialog()方法拋出NullPointerException(Xamarin.Android.Support.v7.MediaRouter)

[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)和一個自定義的點擊監聽器,但是這些都不起作用,並且當我單擊按鈕時它仍然拋出一個錯誤。

任何想法?

回答

1

我今天突然遇到同樣的問題。更新組件到29.0.0.2修復了它。

+0

更新組件並重建項目應該可以解決此問題。 (通常通過重建來解決這個問題)。 –

相關問題