title: android.widget.LinearLayout cannot be cast to android.widget.ImageView?
body: <p>I am trying to show the images on the gridView but getting following errors:-</p>
  
  <pre><code> java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.ImageView
   at com.hubdatasolutions.receiptcloud.ReceiptTabActivity$ReceiptAdapter.getView(ReceiptTabActivity.java:128)
  </code></pre>
  
  <p>row_grid.xml             </p>
  
  <pre><code> &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:padding="5dp" &gt;
      &lt;RelativeLayout 
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
          &lt;ImageView
              android:id="@+id/item_image"
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:layout_marginRight="10dp"
              android:contentDescription="clickedImage"
              android:src="#ffffff" /&gt;
  
          &lt;ImageButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="right"
               android:layout_alignParentRight="true"
               android:src="@drawable/close"
             /&gt;
      &lt;/RelativeLayout&gt;
          &lt;TextView
              android:id="@+id/item_text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="5dp"
              android:textSize="15sp" &gt;
          &lt;/TextView&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>activity_receipt_tab.xml</p>
  
  <pre><code>    &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:tools="http://schemas.android.com/tools"
           android:id="@+id/mainLayout"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="@drawable/menu_bg"
           tools:context=".ReceiptTabActivity" &gt;
           &lt;LinearLayout
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:orientation="vertical" &gt;
               &lt;ImageView
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:background="@drawable/logo" /&gt;
               &lt;GridView
                   android:id="@+id/gridView"
                   android:layout_width="match_parent"
                  android:layout_height="0dp"
                   android:layout_weight="1"
                   android:columnWidth="90dp"
                   android:gravity="center"
                   android:horizontalSpacing="10dp"
                   android:numColumns="auto_fit"
                   android:stretchMode="columnWidth"
                  android:verticalSpacing="10dp" &gt;
               &lt;/GridView&gt;
               &lt;include layout="@layout/tab_footer" /&gt;
           &lt;/LinearLayout&gt;
       &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>ReceptTabActivity.java</p>
  
  <p>This is the java file here I am getting error. This is the file I tried to develop two classes. i am inflating the gridView in the same file.</p>
  
  <pre><code>    public class ReceiptTabActivity extends BaseTabActivity {
  
      GridView mGrid;
      ReceiptAdapter mAdapter;
      ArrayList&lt;ReceiptData&gt; mReceiptList = new ArrayList&lt;ReceiptData&gt;();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_receipt_tab);
  
          mReceiptList = APICaller.getInstance().getReceiptList();
  
  
          mGrid = (GridView) findViewById(R.id.gridView);
      //  mAdapter = new ReceiptAdapter(this, R.layout.receipt_grid_item);
          //mGrid.setAdapter(mAdapter);
          mAdapter = new ReceiptAdapter(this,R.layout.row_grid);
          mGrid.setAdapter(mAdapter);
          APICaller.getInstance().downloadPicData();
      }
  
      @Override
      public void onRefreshData(Refreshable refreshable, int requestCode) {
          if (requestCode == APICaller.DOWNLOAD_PIC_REQUEST_CODE) {
              for (ReceiptData receipt : mReceiptList) {
                  String filePath = receipt.getFilePath();
                  if (filePath != null &amp;&amp; !filePath.isEmpty()) {
                      File file = new File(filePath);
                      Bitmap bitmap = decodeFile(file);
                      if (bitmap != null)
                          receipt.setImage(bitmap);
                      else
                          Log.i("Bitmap", "Still null");
                  } else {
                      Log.i("String", "Still null");
                  }
              }
              mAdapter.notifyDataSetChanged();
          }
      }
  
      // decodes image and scales it to reduce memory consumption
      private Bitmap decodeFile(File f) {
          try {
              // Decode image size
              BitmapFactory.Options o = new BitmapFactory.Options();
              o.inJustDecodeBounds = true;
              BitmapFactory.decodeStream(new FileInputStream(f), null, o);
  
              // The new size we want to scale to
              final int REQUIRED_SIZE = 70;
  
              // Find the correct scale value. It should be the power of 2.
              int scale = 1;
              while (o.outWidth / scale / 2 &gt;= REQUIRED_SIZE
                      &amp;&amp; o.outHeight / scale / 2 &gt;= REQUIRED_SIZE)
                  scale *= 2;
  
              // Decode with inSampleSize
              BitmapFactory.Options o2 = new BitmapFactory.Options();
              o2.inSampleSize = scale;
              return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
          } catch (FileNotFoundException e) {
          }
          return null;
      }
  
      private Bitmap decodeOriginalFile(File f) {
          try {
  
              return BitmapFactory.decodeStream(new FileInputStream(f));
          } catch (FileNotFoundException e) {
          }
          return null;
      }
  
      class ReceiptAdapter extends ArrayAdapter&lt;View&gt; {
          Context mContext;
          int mResource;
          ArrayList&lt;ReceiptData&gt; data = new ArrayList&lt;ReceiptData&gt;();
          public ReceiptAdapter(Context context, int resource) {
              super(context, resource);
              mContext = context;
              mResource = resource;
          }
  
          @Override
          public int getCount() {
              return mReceiptList.size();
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              //ImageButton mainView;
              ImageView mainView;
              //View row = convertView;
              //RecordHolder holder = null;
  
              mainView = (ImageView) findViewById(R.id.item_image);
              //String info = ImageView.getText().toString();
              LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
              mainView = (ImageView) inflater.inflate(mResource, parent, false);
  
  
              Bitmap bitmap = mReceiptList.get(position).getImage();
              if (bitmap != null)
                  mainView.setImageBitmap(bitmap);
  
              return mainView;
          }
  
      }
  }  
  </code></pre>