Search code examples
androidxamarin.androidradio-buttonnosuchmethoderror

Java.Lang.NoSuchMethodError: no non-static method "Landroid/widget/CompoundButton Xamarin.Android


I get this error:

Java.Lang.NoSuchMethodError: no non-static method "Landroid/widget/CompoundButton;.getButtonDrawable()Landroid/graphics/drawable/Drawable;

When I am using a radio button ButtonDrawable like this:

    if(myRadioButton.ButtonDrawable == null)
    {
        //Do Something
    }

I tested the app on android API = 23 (Marshmallow) and it works fine. I get this error for android API < 23 (older than Marshmallow)

I am using Xamarin.Android.Support.Design version 25.3.1

Any idea to fix it?


Solution

  • Elvis is correct, it was my mistake. In case someone has same problem, this how I solved the problem without using get button drawable.

    This code for Xamarin.android but you can convert it to Java.

    //Remove radio button circle    
     radioButton.SetButtonDrawable(new StateListDrawable());
    
    //Set tag = true to know the button drawable is null
    radioButton.Tag = true;
    

    Later in code:

    if(radioButton.tag.Equals(true))
    {
       //Do something
    }