2

尝试扩充 xml 文件时,我的 OnViewModelSet() 函数出现错误。

打电话时

LayoutInflater inflater = LayoutInflater.From(this);
View mainView = inflater.Inflate(Resource.Layout.Main, null);

我收到“java.lang.ClassNotFoundException:Mvx.MvxBindableListView”

这是整个例外:

Android.Views.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxBindableListView

 at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00024] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:145

at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) [0x0003e] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Views.LayoutInflater.cs:543

at AndroidCornerstoneMobile.MainView.OnViewModelSet () [0x00010] in c:\Users\David\Documents\Work\AndroidXamarin\AndroidCornerstoneMobile\Views\MainView.cs:30

at at Cirrious.MvvmCross.Droid.Views.MvxActivityView`1<Core.ViewModels.MainViewModel>.set_ViewModel (Core.ViewModels.MainViewModel) <0x000bb>

at at Cirrious.MvvmCross.ExtensionMethods.MvxViewExtensionMethods.OnViewCreate<Core.ViewModels.MainViewModel> (Cirrious.MvvmCross.Interfaces.Views.IMvxView`1<Core.ViewModels.MainViewModel>,System.Func`1<Core.ViewModels.MainViewModel>) <0x00203>

at at Cirrious.MvvmCross.Droid.ExtensionMethods.MvxAndroidActivityExtensionMethods.OnViewCreate<Core.ViewModels.MainViewModel> (Cirrious.MvvmCross.Droid.Interfaces.IMvxAndroidView`1<Core.ViewModels.MainViewModel>) <0x00297>

at at Cirrious.MvvmCross.Droid.Views.MvxActivityView`1<Core.ViewModels.MainViewModel>.OnCreate (Android.OS.Bundle) <0x000d3>

at at Cirrious.MvvmCross.Binding.Droid.Views.MvxBindingActivityView`1<Core.ViewModels.MainViewModel>.OnCreate (Android.OS.Bundle) <0x000b7>

at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.App.Activity.cs:1837

at at (wrapper dynamic-method) object.8c1f4311-41e4-4a0f-98f2-454a6152589a (intptr,intptr,intptr) <IL 0x00017, 0x00043>

at 

at --- End of managed exception stack trace ---

at android.view.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxBindableListView

at  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)

at  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)

at  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)

at  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)

at  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)

at  at cirrious.mvvmcross.binding.droid.views.MvxBindingActivityView_1.n_onCreate(Native Method)

at  at cirrious.mvvmcross.binding.droid.views.MvxBindingActivityView_1.onCreate(MvxBindingActivityView_1.java:31)

at  at android.app.Activity.performCreate(Activity.java:4539)

at  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)

at  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2013)

at  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2083)

at  at android.app.ActivityThread.access$600(ActivityThread.java:134)

at  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)

at  at android.os.Handler.dispatchMessage(Handler.java:99)

at  at android.os.Looper.loop(Looper.java:137)

at  at android.app.ActivityThread.main(ActivityThread.java:4697)

at  at java.lang.reflect.Method.invokeNative(Native Method)

at  at java.lang.reflect.Method.invoke(Method.java:511)

at  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)

at  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)

at  at dalvik.system.NativeStart.main(Native Method)

at Caused by: java.lang.ClassNotFoundException: Mvx.MvxBindableListView

at  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

at  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)

at  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

at  at android.view.LayoutInflater.createView(LayoutInflater.java:552)

at  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)

at  ... 20 more
4

1 回答 1

5

要扩充 MvvmCross 类,您必须使用类BindingInflate提供的方法MvxActivity。最简单的方法是调用SetContentView()inside OnCreate()or OnViewModelSet()

这些方法通过 MvvmCross 绑定代码路由膨胀,该代码知道如何解释Mvx.缩写名称空间并知道如何解包MvxBind绑定语句。

默认的 Android inflater 不知道这些事情中的任何一个 - 所以我们不能只使用它。

于 2013-03-13T00:47:39.963 回答