Why Fragment cannot be public static class?
<p>I came across such problem: I wanted to have some Fragment as <code>public static</code> member of my <code>Activity</code> class.</p>

<p>But when I put such Fragment to layout file I receive such exception:</p>

<pre><code>Caused by: android.support.v4.app.Fragment$InstantiationException: 
Unable to instantiate fragment com.tst.MainActivity.InnerFragment:
make sure class name exists, is public, 
and has an empty constructor that is public
...
</code></pre>

<p>My code looks like this:</p>

<pre><code>package com.tst;

public final class MainActivity extends SherlockFragmentActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public static class InnerFragment extends SherlockFragment {

        public InnerFragment() {
            super();
        }
        ...
    }
}
</code></pre>

<p>Layout file looks like this:</p>

<pre><code>&lt;LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical" &gt;

  &lt;fragment
        android:id="@+id/inner_fragment"
        android:name="com.tst.MainActivity.InnerFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>Now my question is why such code throws this Exception? As Android should be able to instanitate <code>InnerFragment</code> as it is <code>public static</code>. What is more I used to use <code>public static</code> Fragments and they worked, but on that time I added them programmatically in code not in xml definition.</p>

<p>Regards,
Michal</p>
