2013-07-25 83 views
1

我有一個自定義控件內充氣MvxImageView的問題。錯誤充氣Mvx.MvxImageView

從研究我做了,我發現幾名犯罪嫌疑人

  1. 我應該若有什麼補充的嗎? (我看到這是關於android地圖視圖膨脹錯誤
  2. 我是否創建用戶控件都是錯誤的?我看到了一個建議,使用SetContentView()而不是inflate,因爲它通過mvvmcross mechanisem傳遞了indlate請求,但有自定義視圖沒有這樣的方法

    這裏是自定義控件佈局:

    <?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" /> 
    

這裏是UserCon特倫實現:

public class UserControl : LinearLayout 
{ 
    public UserControl(Context context, IAttributeSet attrs) : base(context,attrs) 
    { 
     LayoutInflater inflater = LayoutInflater.From(context); 
     inflater.Inflate (Resource.Layout.UserControl, this); 
    } 
} 

這裏是我使用它:

<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"/> 

我得到以下異常:

Android.Views.InflateException:二進制XML文件中的行#1:錯誤在/ Users/builder中的Android.Runtime.JNIEnv.CallObjectMethod類(intptr,intptr,Android.Runtime.JValue [])[0x00024]上的類Mvx.MvxImageView /data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:145 在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 在TestApp.UserControl..ctor(Android.Content.Context,Android.Util.IAttributeSet)[0x00011]在C:\用戶\阿米特\文件\項目\ TestApp \ TestApp \ UserControl.cs:20 at at(包裝動態方法)object.bd915d4e-f205-49cd-a1e8-a0532b2db313(intptr,object []) at Java.Interop.TypeManager.n_Activate(intptr,intptr, intptr,intptr,intptr,intptr)在[/ code] /TypeManager.c s:141 at at(wrapper native-to-managed)java.Interop.TypeManager.n_Activate(intptr,intptr,intptr,intptr,intptr,intptr) at(包裝託管到本機)object.wrapper_native_0x40819b9d(intptr ,IntPtr的,IntPtr的,Android.Runtime.JValue [])< 0x00047> 處(包皮代表-調用).invoke_intptr_ __intptr_intptr_intptr_JValue [](IntPtr的,IntPtr的,IntPtr的,Android.Runtime.JValue []) 在Android.Runtime.JNIEnv.CallObjectMethod(intptr,intptr,Android.Runtime.JValue [])/Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/monodroid中的[0x00005] /src/Mono.Android/src/Runtime/JNIEnv.g.cs:141 在Android.Views.LayoutInflater.Inflate(INT,Android.Views.ViewGroup)[0x00043]在/用戶/助洗劑/數據/通道/ MonoDroid的-mlion-MonoDroid的-4.8.0-麩皮CH/9486a4ec /源極/ MonoDroid的/ SRC/Mono.Android /平臺/機器人-8/SRC /生成/ Android.Views.LayoutInflater.cs:422 在Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.CommonInflate(INT ,Android.Views.ViewGroup,Cirrious.MvvmCross.Binding.Droid.Binders.MvxBindingLayoutInflatorFactory)[0x0003c]位於c:\ Projects \ Misc \ MVVMCROSS \ Cirrious \ Cirrious.MvvmCross.Binding中。在Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContext.BindingInflate(int,Android.Views.ViewGroup)中的Droid \ BindingContext \ MvxAndroidBindingContext.cs:58 c:\ Projects \ Misc \ MVVMCROSS \ Cirrious \ Cirrious中的[0x00001]。 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]在c:\ Projects \ Misc \ MVVMCROSS \ Cirrious \ Cirrious.MvvmCross.Binding.Droid \ BindingContext \ MvxBindingContextOwnerExtensions.cs中:18 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 \ P 1)在Cirrious的c:\ Projects \ Misc \ MVVMCROSS \ Cirrious \ Cirrious.MvvmCross \ Views \ MvxViewExtensionMethods.cs:35 上的TestApp.BaseActivity 1<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中的[0x00055]在c:\ Projects \ Misc \ MVVMCROSS \ Cirrious \ Cirrious.MvvmCross.Droid \ Views \ MvxActivityViewExtensions中的MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate(Cirrious.MvvmCross.Droid.Views.IMvxAndroidView,Android.OS.Bundle)[0x0006b]的.cs:50 在Cirrious.MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled(對象,Cirrious.CrossCore.Core.MvxValueEventArgs Android.OS.Bundle > > .invoke_void__this ___ object_TEventArgs(對象,Cirrious.CrossCore.Core.MvxValueEventArgs1) < 0x00067> at Cirrious.CrossCore.Droid。 Views.MvxDelegateExtensionMethods.Raise(System.EventHandler 1<Cirrious.CrossCore.Core.MvxValueEventArgs 1>,object,Android.OS.Bundle)< 0x00113> at Cirrious.CrossCore.Droid.Views.MvxEventSourceActivity.OnCreate(Android.OS.Bundle)[0x00009] in c: \項目\其它\ MVVMCROSS \ CROSSCORE \ Cirrious.CrossCore.Droid \視圖\ MvxEventSourceActivity.cs:23 處TestApp.BaseActivity`1.OnCreate(Android.OS.Bundle)< 0x0005b> 在TestApp.Main.OnCreate(在Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(intptr,intptr,intptr)[0x00010]中的Android.OS.Bundle)[0x00001]位於c:\ Users \ Amit \ Documents \ Projects \ TestApp \ TestApp \ MainActivity.cs中:16 /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(wrapp erd動態方法)object.302eab70-b743-4322-bd6e-c04ded2426ec(intptr,intptr,intptr) at at ---管理異常堆棧跟蹤結束--- at android.view.InflateException:二進制XML文件行#1:錯誤在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698) at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) at android.view中,類Mvx.MvxImageView .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(Ty peManager.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) 處android.view.LayoutInflater.createView(LayoutInflater.java:587) 處android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 處android.view.LayoutInflater.rInflate( LayoutInflater.java:746) at at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 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 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:50 39) 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引起: java.lang.ClassNotFoundException:未在路徑中找到類「Mvx.MvxImageView」:/data/app/TestApp.TestApp-1.apk at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65) 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) 處android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 在... 31多個 在

+0

我真的不明白你想達到什麼。你在誇大一個觀點,然後你就把它扔掉了?無論如何,你會得到一個'ClassNotFoundException',因爲它找不到'Mvx.MvxImageView'。 – Cheesebaron

+0

@ Cheesebaron也許我做錯了什麼。我誇大觀點,然後把它扔掉,你的意思是什麼?我正在嘗試做的是爲我的Xamarin android應用創建一個UserControl等價物。我究竟做錯了什麼。這就是我看到人們在幾篇文章中做的 –

回答

1

我感到困惑,你在做什麼 - 你似乎嘗試在非數據綁定環境中充氣數據綁定對象。

上使用子控制可以幫助這兩個教程:

或者,由於您的佈局沒有自定義功能 - 我t只是XML - 那麼也許你可以考慮只使用Android的<include> xml塊?見http://developer.android.com/training/improving-layouts/reusing-layouts.html

+0

哦,我的上帝!這正是我正在尋找的!非常感謝,經過5個小時的測試和搜索。非常感謝!!! –