title: Android: VerticalGridFragment cause app to crash when using ErrorFragment?
body: <p>I've seen many questions regarding <code>Binary XML file line #2: Binary XML file line #2: Error inflating class fragment</code> but none of them is related to mine and even trying some of the solutions did not work.</p>
  
  <p>My issue is that when I'm using a <code>VerticalGridFragment</code> and I present an <code>ErrorFragment</code> it crashes. However, if I extend my <code>MainFragment</code> to use <code>DetailsFragment</code>, the app does not crash and I am able to use the <code>ErrorFragment</code>.</p>
  
  <p>Here's my sample code:</p>
  
  <p>activity_main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/main_browse_fragment"
      android:name="com.ui.MainFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.ui.MainActivity"
      tools:deviceIds="tv"
      tools:ignore="MergeRootFrame" /&gt;
  </code></pre>
  
  <p>MainActivity.java:</p>
  
  <pre><code>public class MainActivity extends Activity
  {
      private static final String TAG = "MyActivity";
  
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  }
  </code></pre>
  
  <p>MainFragment.java:</p>
  
  <pre><code>public class MainFragment extends VerticalGridFragment
  {
      public final ErrorFragment error = new ErrorFragment();
  
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
  
          displayInternetError();
      }
  
      public void displayInternetError()
      {
          getFragmentManager().beginTransaction().replace(R.id.main_browse_fragment, error)
                  .addToBackStack(null).commit();
  
          error.setImageDrawable(getResources().getDrawable(R.drawable.lb_ic_sad_cloud, null));
          error.setMessage(getResources().getString(R.string.no_internet_message));
          error.setDefaultBackground(true);
  
          error.setButtonText(getResources().getString(R.string.retry_connection));
  
          error.setButtonClickListener(new View.OnClickListener()
          {
              @Override
              public void onClick(View arg0)
              {
  
              }
          });
      }
  
      ...
  }
  </code></pre>
  
  <p>My Logcat:</p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.example.vietmytv_androidtv, PID: 17619
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vietmytv_androidtv/com.example.vietmytv_androidtv.ui.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
      at android.app.ActivityThread.-wrap11(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
      at android.os.Handler.dispatchMessage(Handler.java:102)                    
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
      at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)        
      at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
      at android.app.Activity.setContentView(Activity.java:2166)
      at com.ui.MainActivity.onCreate(MainActivity.java:42)
      at android.app.Activity.performCreate(Activity.java:6237)        
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
      at android.app.ActivityThread.-wrap11(ActivityThread.java)         
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
      at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
      at android.app.Activity.setContentView(Activity.java:2166) 
      at com.ui.MainActivity.onCreate(MainActivity.java:42) 
      at android.app.Activity.performCreate(Activity.java:6237) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v17.leanback.widget.VerticalGridPresenter$ViewHolder android.support.v17.leanback.widget.VerticalGridPresenter.onCreateViewHolder(android.view.ViewGroup)' on a null object reference
      at android.support.v17.leanback.app.VerticalGridFragment.onViewCreated(VerticalGridFragment.java:170)
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:954)
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126) 
      at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1228)
      at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2201)
      at android.app.FragmentController.onCreateView(FragmentController.java:98)
      at android.app.Activity.onCreateView(Activity.java:5546)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
      at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
      at android.app.Activity.setContentView(Activity.java:2166)
      at com.ui.MainActivity.onCreate(MainActivity.java:42)
      at android.app.Activity.performCreate(Activity.java:6237)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
      at android.app.ActivityThread.-wrap11(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
  </code></pre>
  
  <p>Based on how I display my layout, I need to use <code>VerticalGridLayout</code>, but I'm not sure how to use it with <code>ErrorFragment</code>.</p>
  
  <p>Can someone point me in the right direction?</p>
  
  <p>Thanks!</p>