I am having a problem with inflating MvxImageView inside a custom control.
from the research I did I found several suspects
- Should I add if so to what? (i saw this in regards to the android map view inflate error.
Am I creating the User control all wrong? I saw a recommendation to use SetContentView() instead of inflate because it passes the indlate request through the mvvmcross mechanisem but there is no such method in a custom view.
Here is the custom control layout:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res/Com.TasteITAndroidClient" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Mvx.MvxImageView android:scaleType="centerCrop" android:id="@+id/Image" android:layout_width="match_parent" android:layout_height="wrap_content" />
And here is the UserControl implementation:
public class UserControl : LinearLayout
{
public UserControl(Context context, IAttributeSet attrs) : base(context,attrs)
{
LayoutInflater inflater = LayoutInflater.From(context);
inflater.Inflate (Resource.Layout.UserControl, this);
}
}
Here is where I am using it:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TestApp.UserControl
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
I am getting the following exception:
Android.Views.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxImageView
at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00024] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:145
at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.LayoutInflater.cs:422
at TestApp.UserControl..ctor (Android.Content.Context,Android.Util.IAttributeSet) [0x00011] in c:\Users\Amit\Documents\Projects\TestApp\TestApp\UserControl.cs:20
at at (wrapper dynamic-method) object.bd915d4e-f205-49cd-a1e8-a0532b2db313 (intptr,object[])
at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:141
at at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr)
at at (wrapper managed-to-native) object.wrapper_native_0x40819b9d (intptr,intptr,intptr,Android.Runtime.JValue[]) <0x00047>
at at (wrapper delegate-invoke) .invoke_intptr_this__intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[])
at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00005] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:141
at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.LayoutInflater.cs:422
at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.CommonInflate (int,Android.Views.ViewGroup,Cirrious.MvvmCross.Binding.Droid.Binders.MvxBindingLayoutInflatorFactory) [0x0003c] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Binding.Droid\BindingContext\MvxAndroidBindingContext.cs:58
at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.BindingInflate (int,Android.Views.ViewGroup) [0x00001] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Binding.Droid\BindingContext\MvxAndroidBindingContext.cs:37
at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxBindingContextOwnerExtensions.BindingInflate (Cirrious.MvvmCross.Binding.BindingContext.IMvxBindingContextOwner,int,Android.Views.ViewGroup) [0x0000d] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Binding.Droid\BindingContext\MvxBindingContextOwnerExtensions.cs:18
at Cirrious.MvvmCross.Droid.Views.MvxActivity.SetContentView (int) [0x00001] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Droid\Views\MvxActivity.cs:51
at TestApp.Main.InnerViewModelSet () [0x00001] in c:\Users\Amit\Documents\Projects\TestApp\TestApp\MainActivity.cs:21
at at TestApp.BaseActivity1<TestApp.LoginPageViewModel>.OnViewModelSet () <0x00087>
at Cirrious.MvvmCross.Droid.Views.MvxActivity.set_ViewModel (Cirrious.MvvmCross.ViewModels.IMvxViewModel) [0x00009] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Droid\Views\MvxActivity.cs:38
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (Cirrious.MvvmCross.Views.IMvxView,System.Func
1) [0x00055] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross\Views\MvxViewExtensionMethods.cs:35
at Cirrious.MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate (Cirrious.MvvmCross.Droid.Views.IMvxAndroidView,Android.OS.Bundle) [0x0006b] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Droid\Views\MvxActivityViewExtensions.cs:50
at Cirrious.MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled (object,Cirrious.CrossCore.Core.MvxValueEventArgs1<Android.OS.Bundle>) [0x00001] in c:\Projects\Misc\MVVMCROSS\Cirrious\Cirrious.MvvmCross.Droid\Views\MvxActivityAdapter.cs:85
at at (wrapper delegate-invoke) System.EventHandler
11<Android.OS.Bundle>>.invoke_void__this___object_TEventArgs (object,Cirrious.CrossCore.Core.MvxValueEventArgs1) <0x00067>
at at Cirrious.CrossCore.Droid.Views.MvxDelegateExtensionMethods.Raise (System.EventHandler1<Cirrious.CrossCore.Core.MvxValueEventArgs
1>,object,Android.OS.Bundle) <0x00113>
at Cirrious.CrossCore.Droid.Views.MvxEventSourceActivity.OnCreate (Android.OS.Bundle) [0x00009] in c:\Projects\Misc\MVVMCROSS\CrossCore\Cirrious.CrossCore.Droid\Views\MvxEventSourceActivity.cs:23
at at TestApp.BaseActivity`1.OnCreate (Android.OS.Bundle) <0x0005b>
at TestApp.Main.OnCreate (Android.OS.Bundle) [0x00001] in c:\Users\Amit\Documents\Projects\TestApp\TestApp\MainActivity.cs:16
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1561
at at (wrapper dynamic-method) object.302eab70-b743-4322-bd6e-c04ded2426ec (intptr,intptr,intptr)
at
at --- End of managed exception stack trace ---
at android.view.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxImageView
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
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 mono.android.TypeManager.n_activate(Native Method)
at at mono.android.TypeManager.Activate(TypeManager.java:7)
at at testapp.UserControl.(UserControl.java:29)
at at java.lang.reflect.Constructor.constructNative(Native Method)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
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 testapp.Main.n_onCreate(Native Method)
at at testapp.Main.onCreate(Main.java:28)
at at android.app.Activity.performCreate(Activity.java:5104)
at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at at android.app.ActivityThread.access$600(ActivityThread.java:141)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
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:5039)
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:793)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at at dalvik.system.NativeStart.main(Native Method)
at Caused by: java.lang.ClassNotFoundException: Didn't find class "Mvx.MvxImageView" on path: /data/app/TestApp.TestApp-1.apk
at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
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:687)
at ... 31 more
at
ClassNotFoundException
because it cannot findMvx.MvxImageView
. – Cheesebaron