title: android.view.InflateException: Binary XML file line #36: Error inflating class fragment
body: <p>I'm very new to Android Application Development. I know my problem might be simple one. but, I'm sure it is related to layout.</p>
  
  <p>Here's my issue: There's is a <i>listView</i> in the <i>Fragment</i>. When I click the button the new Fragment is added to the <b>ScrollView</b> in the main Layout. When I start the activity one fragment is already added to the activity. So, when I change the rotation the application does not crash.</p>
  
  <p>But, new Fragment is added in the ScrollView after clicking button. But <i>this time</i> when I <b>change</b> the Rotation of the device the Application crashes giving following the error in the end. Can you help me solve this problem. Error occurs only when I change rotaion otherwise app runs fine.</p>
  
  <p>Layout(XML) File activity_another_custom_list_view.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/activity_another_custom_list_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.practices.app.practices.AnotherCustomListViewActivity"
  android:background="@drawable/border"&gt;
  
  
  &lt;Button
      android:text="@string/add_fragments"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/button"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="20dp"
      android:onClick="addfrag"/&gt;
  
  &lt;ScrollView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@id/button"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
  
  
  &lt;fragment
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:name="com.practices.app.practices.AnotherCustomListViewFragment"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true"
      android:id="@+id/fragment"
      /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Fragment Layout another_custom_listview_fragment.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  
  &lt;ListView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/fraglistview"&gt;&lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Java File AnotherCustomListViewActivity.java</p>
  
  <pre><code>package com.practices.app.practices;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.app.Fragment;
  import android.app.FragmentManager;
  import android.app.FragmentTransaction;
  import android.view.View;
  
  public class AnotherCustomListViewActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_another_custom_list_view);
  
  
  }
  
  public void addfrag(View v){
      AnotherCustomListViewFragment f = new AnotherCustomListViewFragment();
      FragmentManager fm = getFragmentManager();
      FragmentTransaction ft = fm.beginTransaction();
      ft.add(R.id.fragment,f);
      ft.commit();
  }
  }
  </code></pre>
  
  <p>Fragment Java Class AnotherCustomListViewFragment</p>
  
  <pre><code>package com.practices.app.practices;
  
  import android.app.Activity;
  import android.app.Fragment;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v7.app.AppCompatActivity;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.Adapter;
  import android.widget.ListAdapter;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  
  
  public class AnotherCustomListViewFragment extends Fragment {
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  }
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.another_custom_listview_fragment, container, false);
  
      String[] str = {"a","b","c","d"};
      ListView fraglist = (ListView) view.findViewById(R.id.fraglistview);
      ListAdapter listadapter = new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_list_item_1, str);
      fraglist.setAdapter(listadapter);
  
      return view;
  }
  }
  </code></pre>
  
  <p>Here's the full Error:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.practices.app.practices/com.practices.app.practices.AnotherCustomListViewActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class fragment
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2426)
                    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3994)
                    at android.app.ActivityThread.access$1000(ActivityThread.java:155)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:135)
                    at android.app.ActivityThread.main(ActivityThread.java:5318)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:372)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:717)
                 Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class fragment
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
                    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
                    at com.practices.app.practices.AnotherCustomListViewActivity.onCreate(AnotherCustomListViewActivity.java:15)
                    at android.app.Activity.performCreate(Activity.java:6024)
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2426) 
                    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3994) 
                    at android.app.ActivityThread.access$1000(ActivityThread.java:155) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:135) 
                    at android.app.ActivityThread.main(ActivityThread.java:5318) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at java.lang.reflect.Method.invoke(Method.java:372) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:717) 
                 Caused by: java.lang.IllegalStateException: Fragment com.practices.app.practices.AnotherCustomListViewFragment did not create a view.
                    at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2145)
                    at android.app.Activity.onCreateView(Activity.java:5373)
                    at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:36)
                    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:77)
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
                    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
                    at com.practices.app.practices.AnotherCustomListViewActivity.onCreate(AnotherCustomListViewActivity.java:15) 
                    at android.app.Activity.performCreate(Activity.java:6024) 
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317) 
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2426) 
                    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3994) 
                    at android.app.ActivityThread.access$1000(ActivityThread.java:155) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:135) 
                    at android.app.ActivityThread.main(ActivityThread.java:5318) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at java.lang.reflect.Method.invoke(Method.java:372) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:717) 
  </code></pre>
  
  <p>I added reply to the answers in comment section but no one is answering.</p>