Unhandled Exception : Android.Views.InflateException

Hello everyone, i am programming this app for my school project and i´ve been getting this problem:

  • When i compile the app in the emulator, everything works fine, but when i compile on my Asus Zenfone 2 Laser - Android 6.0 i am getting this error:

Unhandled Exception:

Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class occurred.

I Get this error when i try to move from Activity3 to Activity4, but this error is non-sense.

Note: All my other activities are very similar to Activity4, and i had this error before with activity3, but i just recompiled it and it worked out.

NOTE 2 = When i get this error, the message "PROJECT stoped" shows up and for some crazy reason it shows up like a TextView (SecondActivity), and then the second activity is loaded, but this time, everything works just fine
Plzz help!

HERE ARE THE ACTIVITIES AND XML´s from act 3 ~ 4

ACT 3.CS

namespace OndeParar
{
[Activity(Label = "ThirdActivity")]
public class ThirdActivity : Activity
{
private List estacionamentos;
private ListView listestacionamentos;
private TextView txt1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
RequestWindowFeature(WindowFeatures.NoTitle);
SetContentView(Resource.Layout.Third);
Typeface robotoregular = Typeface.CreateFromAsset(Assets, "Roboto-Regular.ttf");
Typeface robotolight = Typeface.CreateFromAsset(Assets, "Roboto-Light.ttf");
txt1 = FindViewById(Resource.Id.selecione2);
txt1.SetTypeface(robotolight, TypefaceStyle.Normal);

        estacionamentos = new List<string>();
        estacionamentos.Add("Shopping X");
        estacionamentos.Add("Aeroporto Y");
        estacionamentos.Add("Supermercado Z");
        estacionamentos.Add("Demonstração");

        listestacionamentos = FindViewById<ListView>(Resource.Id.listView1);
        ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, estacionamentos);
        listestacionamentos.Adapter = adapter;
        listestacionamentos.ItemClick += listestacionamentos_ItemClick;
    }

    void listestacionamentos_ItemClick(object sender, AdapterView.ItemClickEventArgs e) {  
        if (e.Position != 3)
        {
            Toast.MakeText(ApplicationContext, "Indisponível no momento.", ToastLength.Long).Show();
        }
        else {
            StartActivity(typeof(QuartaActivity));
            OverridePendingTransition(Resource.Animation.slide_right, Resource.Animation.fade_out);
        }
    }
}

}

ACT4.CS

namespace OndeParar
{
[Activity(Label = "QuartaActivity", MainLauncher = false)]
public class QuartaActivity : Activity
{
SwipeRefreshLayout mSwipeRefreshLayout;
TextView txt1;
ImageView img;

    protected override void OnCreate(Bundle savedInstanceState)
    {

        base.OnCreate(savedInstanceState);
        RequestWindowFeature(WindowFeatures.NoTitle);
        SetContentView(Resource.Layout.QuartoLayout);
        Typeface robotoregular = Typeface.CreateFromAsset(Assets, "Roboto-Regular.ttf");
        Typeface robotolight = Typeface.CreateFromAsset(Assets, "Roboto-Light.ttf");
        txt1 = FindViewById<TextView>(Resource.Id.act4txt3);
        img = FindViewById<ImageView>(Resource.Id.img1);

        txt1.SetTypeface(robotolight, TypefaceStyle.Normal);

        try
        {
            string resultado = GetSQLData("sql10.freemysqlhosting.net", "3306", "sql10176679", "sql10176679", "cxblmShRll", "utf8");

            if (resultado == "1")
            {
                txt1.Text = "Vagas Disponíveis: 0/6";
                img.SetImageResource(Resource.Drawable.VagaOcupada);
            }
            else if (resultado == "0")
            {
                txt1.Text = "Vagas Disponíveis: 1/6";
                img.SetImageResource(Resource.Drawable.VagaLivre);
            }

        }
        catch
        {
            txt1.Text = "Erro de Conexão!";
            img.SetImageResource(Resource.Drawable.SemConexao);
        }

        mSwipeRefreshLayout = FindViewById<SwipeRefreshLayout>(Resource.Id.swipeLayout);

pragma warning disable CS0618 // O tipo ou membro é obsoleto

        mSwipeRefreshLayout.SetColorScheme(Android.Resource.Color.HoloBlueBright, Android.Resource.Color.HoloBlueDark, Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloRedLight);

pragma warning restore CS0618 // O tipo ou membro é obsoleto

        mSwipeRefreshLayout.Refresh += mSwipeRefreshLayout_Refresh;


    }


    void mSwipeRefreshLayout_Refresh(object sender, EventArgs e)
    {

            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += worker_DoWork;
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            worker.RunWorkerAsync();

        try
        {
            string resultado = GetSQLData(MY SERVER STUFF );

            if (resultado == "1")
            {
                txt1.Text = "Vagas Disponíveis: 0/6";
                img.SetImageResource(Resource.Drawable.VagaOcupada);
            }
            else if (resultado == "0")
            {
                txt1.Text = "Vagas Disponíveis: 1/6";
                img.SetImageResource(Resource.Drawable.VagaLivre);
            }

        }
        catch
        {
            txt1.Text = "Erro de Conexão!";
        }
    }






    public string GetSQLData(string server,string port, string database,string userid,string password, string charset)
    {

            MySqlConnection sqlconn;
            string connsqlstring = "Server="+server+";Port="+port+";database="+database+";User Id="+userid+";Password="+password+";charset="+charset;
            sqlconn = new MySqlConnection(connsqlstring);
            sqlconn.Open();
            string queryString = "select ocupada from principal;";
            MySqlCommand sqlcmd = new MySqlCommand(queryString, sqlconn);
            string result = sqlcmd.ExecuteScalar().ToString();
            sqlconn.Close();
            return result;
    }

    void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        RunOnUiThread(() => { mSwipeRefreshLayout.Refreshing = false; });
    }

    void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        //Will run on separate thread
        Thread.Sleep(1000);
    }

}

}

act3 xml

<?xml version="1.0" encoding="utf-8"?>



act4xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/FundoApp3"&gt;








</android.support.v4.widget.SwipeRefreshLayout>

Sign In or Register to comment.