Search code examples
androiddebuggingmonodevelopxamarin.android

Force Close always occuring on android device (even with very simple hello world code)


My university recently got monodroid working in the labs and I've spent the day trying to get to grips with it.

However, upon building the basic tutorial scripts to an actual phone (desire hd and incredible s) they will instantly bring up a force close message.

[EDIT] Ok here goes. This is (in my view), an extremely simple procedure based on the initial monoDevelopProject.

I've left out using the namespace sections for clarity, these are all left default.

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Main);

    // Get our button from the layout resource,
    // and attach an event to it
    Button button = FindViewById<Button>(Resource.Id.MyButton);
    // on button click change button text
    button.Click += delegate { button.Text = string.Format("You clicked the button!") };
}

So, this compiles, builds and runs with no errors on a standard sdk 2.3 emu. But not on an actual device.

I am unable to retrieve any debugging information from the device (I've followed the instructions to allow wifi debugging). With a break point included at line 3 above (base.onCreate(bundle);) it appears to not even step into this method and simply stops the debug after the force close.

I will try and debug this again from the device and get some more details now. I may have gotten something wrong.

I have just tried a few example projects from the xamarin gitHub, ranging from simple layouts to full 3d oGL examples and all return a force close messages upon running on my device. I will look into some of the compiler settings and do a reboot of this system

When I run the debug (green arrow), it doesn't even enable the pause/stop buttons (like it should and does on the emu). Genuinely no idea what's wrong, it's as if the app is being killed as soon as its sent to the device. I have a feeling it's not been installed correctly on these systems as I've tried two computers in the lab now.


Solution

  • In addition to jpobst's answer I'd recommend you get a log viewer for your device and watch it while your app is running. I have no affiliation with these guys but I have found myself using their app again and again. https://market.android.com/details?id=com.nolanlawson.logcat&hl=en