Forum Xamarin.Forms

New VisualStudio forms project, crashes on startup on real device. Android.Views.InflateException:

I created a new solution to isolate this. This is my first time building and running on a actual device using Xamarin.

Device, Galaxy Note 3, is configured properly for debugging; I can make a blank android app, build it and run it on my device from visual studio no worries. The issue appears to be with Xamarin.Forms projects.

Exception is:
Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.Toolbar

Code, exception location in bold:

using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace App11.Droid
{
    [Activity(Label = "App11", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

**            base.OnCreate(bundle);**

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
        }
    }
}

Tried

  • Downloading an older android SDK to setting the compling using..., minmum Android...., and target android... versions all to android 5.0; the version on my device
  • Clearing out the app data\local\xamarin\zips
  • Playing with nuget packages. I've tried updating all, not updating, etc.
    Forms is 2.3.3.180
    Xamarin.Android.* is 24.2.1

I did some googling, in general it appears to be caused by using controls that don't exist after an update, or by dodgy XAML. But I'm using the boilerplate provided by the project type. The app does run correctly in the emulators.

Not sure what else to try.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Playing with nuget packages. I've tried updating all, not updating, etc.
    Forms is 2.3.3.180
    Xamarin.Android.* is 24.2.1

    You've updated things you shouldn't have. Common problem.
    https://redpillxamarin.com/2016/12/23/202-starting-on-the-right-foot/

  • MarkOBrienMarkOBrien USMember

    @ClintStLaurent said:

    Playing with nuget packages. I've tried updating all, not updating, etc.
    Forms is 2.3.3.180
    Xamarin.Android.* is 24.2.1

    You've updated things you shouldn't have. Common problem.
    https://redpillxamarin.com/2016/12/23/202-starting-on-the-right-foot/

    Thanks for you reply, I followed your link, started a new project and followed the directions.

    Same problem occurs :(

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @MarkOBrien

    Ok.... Do me a favor.. Open the NuGet Package Manager for the solution.

    What version of Xamarin.Forms is installed? Click on it and look in the right-hand pane to see the installed version.
    And what are the installed versions of the Xamarin.Android.xxx packages?

  • MarkOBrienMarkOBrien USMember

    @ClintStLaurent

    Thanks for help so far.

    xamarin.forms: 2.3.3.180
    xamarin.Android.xxx 23.3.0

    I took a couple of screenshots too. Any ideas ?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    One last thought... maybe 5.0 on that device can't handle the themeing of FormsAppCompatActivity
    You could try inheriting form the older/simpler FormsApplicationActivity

    In MainActivity.cs comment out your existing class signature and put this on in its place
    public class MainActivity : FormsApplicationActivity

  • MarkOBrienMarkOBrien USMember
    edited January 2017

    Hey thanks for your reply,

    When I do that TabLayoutResource and ToolbarResource no longer exists in the current context. Commenting them out causes a null pointer exception.

    I don't understand the what the boilerplate code does, so I don't know how to debug this. Below is my MainActivity.cs in the Android project.

    namespace App13.Droid
    {
        [Activity(Label = "App13", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
        //public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
        public class MainActivity : Xamarin.Forms.Platform.Android.FormsApplicationActivity
        {
            protected override void OnCreate(Bundle bundle)
            {
               // TabLayoutResource = Resource.Layout.Tabbar;
              //  ToolbarResource = Resource.Layout.Toolbar;
    
                base.OnCreate(bundle);
    
                global::Xamarin.Forms.Forms.Init(this, bundle);
                LoadApplication(new App());
            }
        }
    }
    
Sign In or Register to comment.