title: Android studio, getting android.view.InflateException and can't find any working solution
body: <p>Hours have gone by and i still can't get round this really frustrating error.
  i'm new to android programming so i'm pretty much following tutorials and trying to understand them as i move along. i've also tryed different approaches but keep getting the same error.</p>
  
  <pre><code>        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testapp.scott.mpt/com.testapp.scott.mpt.MyActivity}: android.view.InflateException: Binary XML file line #34: Error inflating class fragment
  </code></pre>
  
  <p>Here's my Fragment Layout (I'm using a shape as a background button. that's not the problem because i've tryed removing it and nothing changed...)</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:orientation="horizontal"
      android:layout_height="match_parent"
      tools:context="com.testapp.scott.mpt.MainToolbarFrag"
      android:background="#ff434343"&gt;
  
  
  &lt;Button
      android:layout_width="96dp"
      android:layout_height="fill_parent"
      android:text="My desk"
      android:id="@+id/BT_Toolbar_MyDesk"
      android:background="@drawable/toolbar_buttonbk"
      android:textSize="18sp" /&gt;
  
  &lt;Button
      android:layout_width="96dp"
      android:layout_height="fill_parent"
      android:text="Exercises"
      android:id="@+id/BT_Toolbar_Exercises"
      android:background="@drawable/toolbar_buttonbk"
      android:layout_gravity="left"
      android:textSize="18sp" /&gt;
  
  &lt;Button
      android:layout_width="96dp"
      android:layout_height="fill_parent"
      android:text="My\nProfile"
      android:id="@+id/BT_Toolbar_MyProfile"
      android:background="@drawable/toolbar_buttonbk"
      android:layout_gravity="left"
      android:textSize="18sp" /&gt;
  
  &lt;Button
      android:layout_width="96dp"
      android:layout_height="fill_parent"
      android:text="Extras"
      android:id="@+id/BT_Toolbar_Extras"
      android:background="@drawable/toolbar_buttonbk"
      android:layout_gravity="left"
      android:textSize="18sp" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The activity in which i would want the fragment to be displayed:</p>
  
  <pre><code>&lt;GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="horizontal"
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MyActivity"
      tools:ignore="MergeRootFrame" &gt;
  
  
  &lt;Space
      android:layout_width="fill_parent"
      android:layout_height="20dp"
      android:layout_row="0"
      android:layout_column="0"
      android:id="@+id/Space0" /&gt;
  
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:textAppearance="?android:attr/textAppearanceMedium"
      android:text="@string/main_welcome"
      android:id="@+id/TV_Main_Welcome"
      android:layout_row="1"
      android:layout_column="0"
      android:textAlignment="center"
      android:singleLine="true"
      android:password="false"
      android:inputType="none"
      android:gravity="center"
      android:textStyle="italic"
      android:layout_gravity="left|top" /&gt;
  
  &lt;fragment
      android:layout_width="wrap_content"
      android:layout_height="74dp"
      class="com.testapp.scott.mpt.MainToolbarFrag"
      android:id="@+id/fragment"
      android:layout_row="30"
      android:layout_column="0"
      tools:layout="@layout/fragment_maintoolbar" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>My Fragment Java Class:</p>
  
  <pre><code>package com.testapp.scott.mpt;
  
  import android.app.Activity;
  import android.net.Uri;
  import android.os.Bundle;
  import android.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  /**
   * A simple {@link Fragment} subclass.
   * Activities that contain this fragment must implement the
   * {@link MainToolbarFrag.OnFragmentInteractionListener} interface
   * to handle interaction events.
   * Use the {@link MainToolbarFrag#newInstance} factory method to
   * create an instance of this fragment.
   *
   */
  
  public class MainToolbarFrag extends Fragment {
      // TODO: Rename parameter arguments, choose names that match
      // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
      private static final String ARG_PARAM1 = "param1";
      private static final String ARG_PARAM2 = "param2";
  
      // TODO: Rename and change types of parameters
      private String mParam1;
      private String mParam2;
  
      private OnFragmentInteractionListener mListener;
  
      /**
       * Use this factory method to create a new instance of
       * this fragment using the provided parameters.
       *
       * @param param1 Parameter 1.
       * @param param2 Parameter 2.
       * @return A new instance of fragment MainToolbarFrag.
       */
      // TODO: Rename and change types and number of parameters
      public static MainToolbarFrag newInstance(String param1, String param2) {
          MainToolbarFrag fragment = new MainToolbarFrag();
          Bundle args = new Bundle();
          args.putString(ARG_PARAM1, param1);
          args.putString(ARG_PARAM2, param2);
          fragment.setArguments(args);
          return fragment;
      }
      public MainToolbarFrag() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (getArguments() != null) {
              mParam1 = getArguments().getString(ARG_PARAM1);
              mParam2 = getArguments().getString(ARG_PARAM2);
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_maintoolbar, container, false);
      }
  
      // TODO: Rename method, update argument and hook method into UI event
      public void onButtonPressed(Uri uri) {
          if (mListener != null) {
              mListener.onFragmentInteraction(uri);
          }
      }
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
          try {
              mListener = (OnFragmentInteractionListener) activity;
          } catch (ClassCastException e) {
              throw new ClassCastException(activity.toString()
                      + " must implement OnFragmentInteractionListener");
          }
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
          mListener = null;
      }
  
      /**
       * This interface must be implemented by activities that contain this
       * fragment to allow an interaction in this fragment to be communicated
       * to the activity and potentially other fragments contained in that
       * activity.
       * &lt;p&gt;
       * See the Android Training lesson &lt;a href=
       * "http://developer.android.com/training/basics/fragments/communicating.html"
       * &gt;Communicating with Other Fragments&lt;/a&gt; for more information.
       */
      public interface OnFragmentInteractionListener {
          // TODO: Update argument type and name
          public void onFragmentInteraction(Uri uri);
      }
  
  }
  </code></pre>
  
  <p>And my main Activity class:</p>
  
  <pre><code>package com.testapp.scott.mpt;
  
  import android.app.Activity;
  import android.app.Fragment;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.testapp.scott.mpt.MyClasses.Constants;
  import com.testapp.scott.mpt.MyClasses.Exercises;
  import com.testapp.scott.mpt.MyClasses.UserData;
  import com.testapp.scott.mpt.MyClasses.deskData;
  
  import org.xmlpull.v1.XmlPullParser;
  import org.xmlpull.v1.XmlPullParserException;
  import org.xmlpull.v1.XmlPullParserFactory;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.text.ParseException;
  
  
  public class MyActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_my);
          if (savedInstanceState == null) {
              getFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment())
                      .commit();
  
  
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.my, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      /**
       * A placeholder fragment containing a simple view.
       */
      public static class PlaceholderFragment extends Fragment {
  
          public PlaceholderFragment() {
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.activity_my, container, false);
              return rootView;
          }
      }
  }
  </code></pre>
  
  <p>And FInally this is my Log:</p>
  
  <pre><code>10-13 20:51:54.974    1678-1678/com.testapp.scott.mpt D/dalvikvm﹕ Late-enabling CheckJNI
  10-13 20:51:54.994    1678-1684/com.testapp.scott.mpt D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
  10-13 20:51:55.074    1678-1678/com.testapp.scott.mpt D/AndroidRuntime﹕ Shutting down VM
  10-13 20:51:55.074    1678-1678/com.testapp.scott.mpt W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41941d88)
  10-13 20:51:55.074    1678-1678/com.testapp.scott.mpt E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.testapp.scott.mpt, PID: 1678
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testapp.scott.mpt/com.testapp.scott.mpt.MyActivity}: android.view.InflateException: Binary XML file line #34: Error inflating class fragment
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:212)
              at android.app.ActivityThread.main(ActivityThread.java:5135)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: android.view.InflateException: Binary XML file line #34: Error inflating class fragment
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:297)
              at android.app.Activity.setContentView(Activity.java:1929)
              at com.testapp.scott.mpt.MyActivity.onCreate(MyActivity.java:32)
              at android.app.Activity.performCreate(Activity.java:5231)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:212)
              at android.app.ActivityThread.main(ActivityThread.java:5135)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.ClassCastException: com.testapp.scott.mpt.MyActivity@44aea5d0 must implement OnFragmentInteractionListener
              at com.testapp.scott.mpt.MainToolbarFrag.onAttach(MainToolbarFrag.java:84)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:853)
              at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1044)
              at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1146)
              at android.app.Activity.onCreateView(Activity.java:4786)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:297)
              at android.app.Activity.setContentView(Activity.java:1929)
              at com.testapp.scott.mpt.MyActivity.onCreate(MyActivity.java:32)
              at android.app.Activity.performCreate(Activity.java:5231)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:212)
              at android.app.ActivityThread.main(ActivityThread.java:5135)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Thanks guys!</p>