0
votes

I am new to Xamarin Forms. I have made an Entry renderer for Android. The custom renderer works fine on Android emulator but the app crashes when i deploy it on real android device. Any suggestions about that !

Here is the Code!

Entry Class

namespace ARO {
public class Rounded_Entry: Entry

{

}

}

Android Renderer Class

[assembly:ExportRenderer(typeof(Rounded_Entry),typeof(RoundedEntryRendererAndroid))]

namespace ARO.Droid {

public class RoundedEntryRendererAndroid : EntryRenderer
{
    public RoundedEntryRendererAndroid(Context context) : base(context)
    {

    }
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);
        if (e.OldElement == null)
        {
            //Control.SetBackgroundResource(Resource.Layout.layout1);
            var gradientDrawable = new GradientDrawable();
            gradientDrawable.SetCornerRadius(60f);
            gradientDrawable.SetStroke(5, Android.Graphics.Color.DeepPink);
            gradientDrawable.SetColor(Android.Graphics.Color.LightGray);
            Control.SetBackground(gradientDrawable);

            Control.SetPadding(50, Control.PaddingTop, Control.PaddingRight,
                Control.PaddingBottom);
        }
    }
}

}

1
Suggestion is that you should show your code or chances that someone can help are less than that you can fix the error...Ivan Ičin
@IvanIčin added the code.Usman Zafer
Try changing your if statement i.e. if (Control != null && e !=null). The protection against Control being seems to be essential, see here docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/…Mouse On Mars
I have new a simple xamarin forms solution, and modify it using your rendering code, and test it on my Android device, it works all right. I think maybe the issue is raised in elsewhere of your code. It would help to solve the problem if you attach the full code or at least the code associated with rendering.Jack Hua

1 Answers

0
votes

You need this line in renderer

if (Control == null)
    return;