title: Occasional Binary XML file line #XX: Error inflating class <unknown>
body: <p>I have a main activity, that holds the main menu. This menu has an option to start a second activity, which is a <code>SurfaceView</code> descendent. </p>
  
  <p>I'm getting this error several times, but not always. I need to perform the process of calling the second activity via the first activity's menu button, and then returning to the first activity. Eventually (Usually on the 7th repetition), the error happens when the 2nd. activity is being launched. Whitout the debugger, the phone screen becomes black and is blocked for about 30 or more seconds, then I see the dialog to close it. In debugger, the app stops on this exception.</p>
  
  <p>My layout file for the second activity is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;com.myapp.MySecActivity
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:id="@+id/sec_view"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>I have a Class <code>MySecActivity</code>, with loads this layout on constructor.</p>
  
  <p>I figured out that I'm getting an <code>InflateException</code> on <code>setContentView</code>. I'm checking the id I pass to <code>setContentView</code> and it's the same, not null, on all conditions: </p>
  
  <pre><code>int id = getResources().getIdentifier("mylayout", "layout", getPackageName());
  
  if (id&lt;= 0) {
      id= 0;  // just for debugging
  } else {
     try {
         setContentView(id);
      } catch (InflateException e) {
         error = true;
      }
  }
  </code></pre>