Xamarin Android ViewRenderer<Editor, TextInputLayout> ctor throws null reference

403 Views Asked by At

tl;dr: CustomRenderer with ViewRenderer<Entry, TextInputLayout> works, CustomRenderer with ViewRenderer<Editor, TextInputLayout> does not.

I have created an EditText with floating labels via a CustomRenderer: Android Design Example

Rendering with Entry class:

PCL:

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

Android Project:

[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);
        //[...]
    }
}

This works perfectly fine, and I got my wonderful entry with a floating hint using the TextInputLayout given by the android platform.

Now I wanted to do this for an Editor as well.

Rendering with Entry class:

PCL:

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

Android Project:

[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);
        //[...]
    }
}

But this throws a null reference exception in the ctor. I tested it with both ViewRenderers (appcompat, nonappcompat), with a basic ctor, with the ctor and context signature, nevertheless, it always throws the same error shown below:

JNI DETECTED ERROR IN APPLICATION: JNI CallObjectMethodA called with pending exception android.runtime.JavaProxyThrowable: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Java.Lang.ClassNotFoundException: Didn't find class "md541a10de1a99b1e04dd7b48feb368a279.MyFloatEditor_Droid" on path: DexPathList[[zip file "/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/armeabi-v7a, /system/lib, /vendor/lib]] at Java.Interop.JniEnvironment+Types.FindClass(System.String classname)[0x00114] in <438784097c4b4b56a7da6ca9301bc3c6>:0

at Java.Interop.JniType..ctor(System.String classname) [0x00006] in <438784097c4b4b56a7da6ca9301bc3c6>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods..ctor (System.Type declaringType)[0x00064] in <438784097c4b4b56a7da6ca9301bc3c6>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.GetConstructorsForType (System.Type declaringType)[0x0002c] in <438784097c4b4b56a7da6ca9301bc3c6>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.StartCreateInstance (System.String constructorSignature, System.Type declaringType, Java.Interop.JniArgumentValue* parameters)[0x00032] in <438784097c4b4b56a7da6ca9301bc3c6>: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\Release\generated\src\Xamarin.Forms.Platform.Android.FormsViewGroup.cs:89 at Xamarin.Forms.Platform.Android.VisualElementRenderer1[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.ViewRenderer2[TView, TNativeView]..ctor (Android.Content.Context context)[0x00000] in D:\agent_work\1\s\Xamarin.Forms.Platform.Android\ViewRenderer.cs:25 at 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\AppCompat\ViewRenderer.cs:8 at MyProject.Droid.Renderer.MyFloatEditor_Droid..ctor(Xamarin.Forms.Platform.Android.FormsAppCompatActivity context) [0x00000] in D:\Workspaces\HelloWorld\HelloWorld.MyProject\MyProject\MyProject\MyProject.Android\Renderer\MyFloatEditor_Droid.cs:41 at(wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke(System.Reflection.MonoCMethod, object, object[], System.Exception&) at System.Reflection.MonoCMethod.InternalInvoke(System.Object obj, System.Object[] parameters) [0x00002] in <657aa8fea4454dc898a9e5f379c58734>:0

0

There are 0 best solutions below