System.InvalidCastException: Unable to convert instance of type 'Android.Widget.Space'...

FotalFotal Member ✭✭✭

Hi, I'm new to Xamarin and Android. Could you help fix the error ?

Unhandled Exception:
System.InvalidCastException: Unable to convert instance of type 'Android.Widget.Space' to type 'Android.Widget.Button'. occurred

`protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.login_layout);

// Error this
var loginButton = FindViewById<Button>(Resource.Id.loginButton);
loginButton.Click += LoginButton_Click;

var user = AppController.SharedInstance.GetStoredUser();
if (user != null)
{
    AppController.SharedInstance.Autologin(user);
    StartActivity(typeof(WelcomeActivity));
}

}`

1.png 156.1K

Answers

  • FotalFotal Member ✭✭✭

    Login button:
    <Button android:id="@+id/loginButton" android:text="@string/loginButton" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="0.2" style="@style/PrimaryButton" />

Sign In or Register to comment.