После обновления с 3.5 до 3.5.1 я получаю ошибки, раздувающие фрагменты в моем проекте Xamarin.Android.Каков правильный способ реализации фрагментов в MvvmCross 3.5.1
Unable to start activity ComponentInfo{xxx.xxx/md51537e9497dba76724980c8d1dff85301.MyView}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class md51537e9497dba76724980c8d1dff85301.LoginView that is not a Fragment
В чем причина этой ошибки? Существуют ли изменения в 3.5.1?
Мой Фрагмент определен как
public class LoginFormView : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignore = base.OnCreateView(inflater, container, savedInstanceState);
return this.BindingInflate(Resource.Layout.LoginFormView, null);
}
}
Я включил поддержку V4 через магазин Xamarin компонентов.
Я раздувать свой фрагмент с помощью:
public class LoginView : BaseMvxFragmentActivity
{
...
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.LoginView);
_loginForm = (LoginFormView)SupportFragmentManager.FindFragmentById(Resource.Id.sub_login_form);
_loginForm.ViewModel = MyViewModel.LoginFormViewModel;
}
...
}
Update 1
Мой макет axml является следующим
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<!-- Snip -->
<LinearLayout
android:id="@+id/InnerRelativeLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:padding="10dp">
<fragment
class="com.namespace.LoginFormView"
android:id="@+id/sub_login_form"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Visibility ShowLoginFormViewModel,Converter=Visibility" />
Update 2
Он работает фи пе, когда я построю на физическое устройство
Update 3
Если добавить [Register]
согласно предложению CheeseBaron в то изменения приводят к:
[MonoDroid] Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.namespace.Droid.Views.LoginFormView that is not a Fragment
Подробнее:
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() <IL 0x00011, 0x0004b>
[MonoDroid] at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue*) [0x00064] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:195
[MonoDroid] at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup,bool) [0x00082] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-16/src/generated/Android.Views.LayoutInflater.cs:687
[MonoDroid] at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.CommonInflate (int,Android.Views.ViewGroup,Cirrious.MvvmCross.Binding.Droid.Binders.IMvxLayoutInfactorFactory,bool) <IL 0x00030, 0x00136>
[MonoDroid] at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.BindingInflate (int,Android.Views.ViewGroup,bool) <IL 0x00015, 0x000a5>
[MonoDroid] at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.BindingInflate (int,Android.Views.ViewGroup) <IL 0x00004, 0x00044>
[MonoDroid] at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxBindingContextOwnerExtensions.BindingInflate (Cirrious.MvvmCross.Binding.BindingContext.IMvxBindingContextOwner,int,Android.Views.ViewGroup) <IL 0x0000f, 0x000f5>
[MonoDroid] at Cirrious.MvvmCross.Droid.Fragging.MvxFragmentActivity.SetContentView (int) <IL 0x00003, 0x00037>
[MonoDroid] at com.namespace.Droid.Views.LoginView.OnCreate (Android.OS.Bundle) [0x0000e] in /xxx/Ccom.namespace.Droid/Views/LoginView.cs:34
[MonoDroid] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-16/src/generated/Android.App.Activity.cs:2374
[MonoDroid] at (wrapper dynamic-method) object.facfe989-fd2b-40d3-bf63-959b844af987 (intptr,intptr,intptr) <IL 0x00017, 0x0002b>
Изменения в инфляции Android в 3.5.1 - вызваны для решения изменений пакета поддержки Android Xam - примечание по выпуску - http://slodge.blogspot.co.uk/. Я подозреваю, что сообщение о инфляции, которое вы цитируете, не поступает из MvvmCross ... так что моя кишка говорит мне, что это скорее связано с изменениями Xam, чем с различиями Mvx. Разумеется, предложение childbaron по добавлению '[Register]', а затем очистка и перестроение, похоже, может помочь. – Stuart
Спасибо, но я добавил [Register] и выполнил команду Clean/Rebuild, но все равно получаю ту же ошибку. –
Если вы все еще получаете ту же ошибку, то есть о md51537e9497dba76724980c8d1dff85301', то это означает, что 'Register' не работает. – Stuart