I am trying to use a grid with a custom component but when I try to
inflate the view I get the following exception:

12-02 04:18:07.790: ERROR/AndroidRuntime(1146): Uncaught handler:
thread main exiting due to uncaught exception
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):
java.lang.ClassCastException: android.widget.AbsListView$LayoutParams
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.measureVertical(LinearLayout.java:323)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.GridView.onMeasure(GridView.java:937)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.measureVertical(LinearLayout.java:461)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewRoot.performTraversals(ViewRoot.java:620)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1103)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.os.Handler.dispatchMessage(Handler.java:88)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.os.Looper.loop(Looper.java:123)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.app.ActivityThread.main(ActivityThread.java:3742)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
java.lang.reflect.Method.invokeNative(Native Method)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
java.lang.reflect.Method.invoke(Method.java:515)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
dalvik.system.NativeStart.main(Native Method)

Here is the code I am using to try to inflate the view:

@Override
public View getView(int index, View convertView, ViewGroup parent)
{
        View iconLayout;
        ImageView icon;
        TextView fileName;

        if (convertView == null)
        {
                iconLayout = View.inflate(FileBrowser.this, R.layout.icon, 
null);

                icon = (ImageView)iconLayout.findViewById(R.id.Icon);
                icon.setScaleType(ImageView.ScaleType.FIT_CENTER);
                icon.setLayoutParams(new GridView.LayoutParams(50, 50));

                fileName = (TextView)iconLayout.findViewById(R.id.FileName);
        }
        else
        {
                iconLayout = convertView;
                icon = (ImageView)convertView.findViewById(R.id.Icon);
                fileName = (TextView)convertView.findViewById(R.id.FileName);
        }

        icon.setImageResource(getIcon(index));
        fileName.setText(mFiles.get(index).getName());

        return iconLayout;
}

and here is the layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android";
        android:orientation="vertical"
        android:id="@+id/IconLayout">

        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/Icon"
                android:maxHeight="48px"
                android:maxWidth="48px"
                android:minHeight="48px"
                android:minWidth="48px" />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/FileName"
                android:maxLength="15"
                android:maxLines="1" />
</LinearLayout>

Does anyone know what is causing this exception?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to