Xamarin Android ViewRenderer <editor,textinputlayout =“”> ctor抛出空引用

时间:2017-12-19 11:18:14

标签: java c# android xamarin textinputlayout

TL; DR: CustomRenderer与ViewRenderer&lt; 条目,TextInputLayout&gt;作品, CustomRenderer与ViewRenderer&lt; 编辑器,TextInputLayout&gt;没有。

我通过CustomRenderer创建了一个包含浮动标签的EditText: Android Design Example

使用Entry类进行渲染

PCL:

public class MyFloatEntry : Entry { /*...*/ }

Android项目:

[assembly: ExportRenderer(typeof(MyFloatEntry), typeof(MyFloatEntry_Droid))]
namespace MyProject.Droid.Renderer
{
    public class MyFloatEntry_Droid : ViewRenderer<MyFloatEntry, TextInputLayout>, ITextWatcher, TextView.IOnEditorActionListener
    {
        public MyFloatEntry_Droid(Context context) : base(context)
        {
            //[...]
        }
    }
}

    protected override void OnElementChanged(ElementChangedEventArgs<MyFloatEntry> e)
    {
        base.OnElementChanged(e);
        //[...]
    }
}

这非常好用,我使用android平台给出的TextInputLayout获得了一个浮动提示的精彩条目。

现在我也想为编辑做这件事。

使用Entry类进行渲染

PCL:

public class MyFloatEditor : Editor{ /*...*/ }

Android项目:

[assembly: ExportRenderer(typeof(MyFloatEditor), typeof(MyFloatEditor_Droid))]
namespace MyProject.Droid.Renderer
{
    public class MyFloatEditor_Droid : ViewRenderer<MyFloatEditor, TextInputLayout>, ITextWatcher, TextView.IOnEditorActionListener
    {
        public MyFloatEditor_Droid(Context context) : base(context) //throws "class not found"
        {
            //[...]
        }
    }
}

    protected override void OnElementChanged(ElementChangedEventArgs<MyFloatEditor> e)
    {
        base.OnElementChanged(e);
        //[...]
    }
}

但是这会在ctor中抛出一个空引用异常。 我用ViewRenderers(appcompat,nonappcompat)测试了它,带有基本ctor,带有ctor和上下文签名,然而,它总是抛出下面显示的相同错误:

  

应用程序中的JNI检测错误:JNI调用挂起异常的CallObjectMethodA android.runtime.JavaProxyThrowable:System.Reflection.TargetInvocationException:调用目标抛出了异常。 ---&GT; Java.Lang.ClassNotFoundException:没找到类&#34; md541a10de1a99b1e04dd7b48feb368a279.MyFloatEditor_Droid&#34; on path:DexPathList [[zip file&#34; /data/app/MyProject.Android-1/base.apk"],nativeLibraryDirectories = [/ data / app / MyProject.Android-1 / lib / arm / system /fake-libs,/ data / app / MyProject.Android-1 / base.apk!/ lib / arababi-v7a,/ system / lib,/ vendor / lib]],位于Java.Interop.JniEnvironment + Types.FindClass(系统.string classname)[0x00114] in&lt; 438784097c4b4b56a7da6ca9301bc3c6&gt;:0

     

at Java.Interop.JniType..ctor(System.String classname)[0x00006] in   &lt; 438784097c4b4b56a7da6ca9301bc3c6&gt;:0 at   Java.Interop.JniPeerMembers + JniInstanceMethods..ctor(System.Type   声明类型)[0x00064]在&lt; 438784097c4b4b56a7da6ca9301bc3c6&gt;:0 at   Java.Interop.JniPeerMembers + JniInstanceMethods.GetConstructorsForType   (System.Type declaringType)[0x0002c] in   &lt; 438784097c4b4b56a7da6ca9301bc3c6&gt;:0 at   Java.Interop.JniPeerMembers + JniInstanceMethods.StartCreateInstance   (System.String constructorSignature,System.Type declaringType,   Java.Interop.JniArgumentValue *参数)[0x00032] in   &lt; 438784097c4b4b56a7da6ca9301bc3c6&gt;:0 at   Xamarin.Forms.Platform.Android.FormsViewGroup..ctor(Android.Content.Context   p0)[0x00046] in   d:\ agent_work \ 1 \ S \ Xamarin.Forms.Platform.Android.FormsViewGroup \ OBJ \发布\产生\ SRC \ Xamarin.Forms.Platform.Android.FormsViewGroup.cs:89   在   Xamarin.Forms.Platform.Android.VisualElementRenderer 1[TElement]..ctor (Android.Content.Context context)[0x00012] in D:\agent\_work\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:30 at Xamarin.Forms.Platform.Android.ViewRenderer 2 [TView,   TNativeView] .. ctor(Android.Content.Context context)[0x00000] in   d:\ agent_work \ 1 \ S \ Xamarin.Forms.Platform.Android \ ViewRenderer.cs:25   在Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer`2 [TView,   TControl] .. ctor(Android.Content.Context context)[0x00000] in   d:\ agent_work \ 1 \ S \ Xamarin.Forms.Platform.Android \程序兼容性\ ViewRenderer.cs:8   在   MyProject.Droid.Renderer.MyFloatEditor_Droid..ctor(Xamarin.Forms.Platform.Android.FormsAppCompatActivity   上下文)[0x00000] in   d:\工作区\的HelloWorld \ HelloWorld.MyProject \ MyProject的\ MyProject的\ MyProject.Android \渲染\ MyFloatEditor_Droid.cs:41   at(包装器托管到原生)   System.Reflection.MonoCMethod:InternalInvoke(System.Reflection.MonoCMethod,   object,object [],System.Exception&amp;)at   System.Reflection.MonoCMethod.InternalInvoke(System.Object obj,   System.Object []参数)[0x00002] in   &LT; 657aa8fea4454dc898a9e5f379c58734&GT;:0

0 个答案:

没有答案