ClassCastException when inflating a FrameLayout in a GridView
<p>I'm trying to inflate a FrameLayout in a GridView and I'm getting an exception. Here is the getView method from the adapter (a subclass of BaseAdapter):</p>

<pre><code>public View getView(int position, View convertView, ViewGroup parent) {
    // TODO: Create compound view with image and name overlayed on top
    FrameLayout personFrame;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        personFrame = (FrameLayout)inflater.inflate(R.layout.thumbnail, null);
        //personFrame = (FrameLayout)View.inflate(mContext, R.layout.thumbnail, null);
        personFrame.setLayoutParams(new GridView.LayoutParams(85,85));
    } else {
        personFrame = (FrameLayout) convertView;
    }
</code></pre>

<p>.... and so on</p>

<p>Here's the layout I'm inflating:</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="85px"
android:layout_height="85px"&gt;
&lt;ImageView
    android:id="@+id/thumbnail_image"
    android:layout_height="85px"
    android:padding="2px"
    android:layout_width="85px"
    android:scaleType="centerCrop" /&gt;
&lt;TextView
    android:id="@+id/person_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dip"
    android:layout_gravity="center_horizontal|bottom"

    android:padding="2dip"

    android:background="#AA000000"
    android:textColor="#ffffffff"

    android:text="Me" /&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>I've tried with and without setting the LayoutParams explicitly and I get the same exception each time, which is:</p>

<pre><code>E/AndroidRuntime(  420): java.lang.ClassCastException:        android.widget.FrameLayout$LayoutParams
E/AndroidRuntime(  420):    at android.widget.GridView.onMeasure(GridView.java:934)
E/AndroidRuntime(  420):    at android.view.View.measure(View.java:8171)
E/AndroidRuntime(  420):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
E/AndroidRuntime(  420):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
E/AndroidRuntime(  420):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
E/AndroidRuntime(  420):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
E/AndroidRuntime(  420):    at android.view.View.measure(View.java:8171)
E/AndroidRuntime(  420):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
E/AndroidRuntime(  420):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
E/AndroidRuntime(  420):    at android.view.View.measure(View.java:8171)
E/AndroidRuntime(  420):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
E/AndroidRuntime(  420):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
E/AndroidRuntime(  420):    at android.view.View.measure(View.java:8171)
E/AndroidRuntime(  420):    at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
E/AndroidRuntime(  420):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
E/AndroidRuntime(  420):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  420):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  420):    at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  420):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  420):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  420):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  420):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  420):    at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Can anyone point out where I've gone wrong here? 
Many thanks</p>
