android – GridView is not showing any item-ThrowExceptions

Exception or error:

This is my layout and the part where I have place gridView, but no item is showing in the preview or in the app:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <variable
            name="viewmodel"
            type="com.kreeti.gogal.ui.profile.ProfileViewModel" />
    </data>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="15dp">

                <TextView
                    style="@style/secondary_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/select_photos" />

                <GridView
                    android:id="@+id/gridView"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:numColumns="3"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:stretchMode="spacingWidthUniform" />
           </LinearLayout>
        </androidx.coordinatorlayout.widget.CoordinatorLayout>
    </ScrollView>
</layout>

This is the part where I am setting the adapter,

        gridView.adapter = ImageAdapter(this, R.layout.image_card, Array(6, {R.drawable.filled_rectangle} ))

Even if I set some item statically in my layout they are not showing in the gridView, I can’t figure out what the problem is!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *