充气期间的MvvmCross例外情况

时间:2018-05-10 13:48:32

标签: android xamarin.android mvvmcross

任何人都可以帮我解决以下问题。

我尝试使用MvvmCross中的以下代码更新片段中的活动主题。

代码

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view=null;
            if(FragmentId==Resource.Layout.my_form)
            {
                Context contextThemeWrapper = new ContextThemeWrapper(Activity, Resource.Style.MyTheme_IntakeForm);

                // clone the inflater using the ContextThemeWrapper
                LayoutInflater localInflater = inflater.CloneInContext(contextThemeWrapper);

                view=localInflater.Inflate(Resource.Layout.my_form, container, false);

            }

异常

Could not activate JNI Handle 0xbfa862c8 (key_handle 0x58f5101) of Java type 'mvvmcross/binding/droid/views/MvxSpinner' as managed type 'MvvmCross.Binding.Droid.Views.MvxSpinner'.

内部异常

        {MvvmCross.Platform.Exceptions.MvxException: bindingContext is null during MvxAdapter creation - Adapter's should only be created when a specific binding context has been placed on the stack
      at MvvmCross.Binding.Droid.Views.MvxAdapter..ctor (Android.Content.Context context, MvvmCross.Binding.Droid.BindingContext.IMvxAndroidBindingContext bindingContext) [0x00032] in C:\projects\mvvmcross\MvvmCross\Binding\Droid\Views\MvxAdapter.cs:54 
      at MvvmCross.Binding.Droid.Views.MvxAdapter..ctor (Android.Content.Context context) [0x00000] in C:\projects\mvvmcross\MvvmCross\Binding\Droid\Views\MvxAdapter.cs:44 
      at MvvmCross.Binding.Droid.Views.MvxSpinner..ctor (Android.Content.Context context, Android.Util.IAttributeSet attrs) [0x00000] in C:\projects\mvvmcross\MvvmCross\Binding\Droid\Views\MvxSpinner.cs:23 
      at (wrapper dynamic-method) System.Object.5e8d0b16-077f-459f-9215-45a9d71443b1(intptr,object[])
      at Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass, System.IntPtr typename_ptr, System.IntPtr signature_ptr, System.IntPtr jobject, System.IntPtr parameters_ptr) [0x000df] in <ff199c98c3f84852925dd37a0ef6113a>:0 }

谢谢,

1 个答案:

答案 0 :(得分:0)

我认为您应该确保绑定上下文不为null。尝试添加以下行:

this.EnsureBindingContextIsSet(inflater);