title: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 on CardView
body: <p>I am getting this error as I am not able to pass my parcelable to another activity. I would like to have the Image and the text from my cardView to be passed onto my new activity for each cardview. However, I am receiving thisd error called java.lang.IndexOutOfBoundsException: Index: 0, Size: 0. Can I please get some help? Thanks.</p>
  
  <p>Here is the error code </p>
  
  <pre><code>    E/AndroidRuntime: FATAL EXCEPTION: main
      Process: android.com.example.weddingappfinale, PID: 12694
      java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
          at java.util.ArrayList.get(ArrayList.java:437)
          at android.com.example.weddingappfinale.MuaActivity$1.onItemClick(MuaActivity.java:55)
          at Adapters.MuaAdapter$MuaViewHolder$2.onClick(MuaAdapter.java:59)
          at android.view.View.performClick(View.java:7125)
          at android.view.View.performClickInternal(View.java:7102)
          at android.view.View.access$3500(View.java:801)
          at android.view.View$PerformClick.run(View.java:27336)
          at android.os.Handler.handleCallback(Handler.java:883)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:214)
          at android.app.ActivityThread.main(ActivityThread.java:7356)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
  I/Process: Sending signal. PID: 12694 SIG: 9
  
  Here is my Adapter:
  
  
      package Adapters;
  
  import android.com.example.weddingappfinale.MuaView;
  import android.com.example.weddingappfinale.R;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Filter;
  import android.widget.Filterable;
  import android.widget.ImageButton;
  import android.widget.TextView;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class MuaAdapter extends RecyclerView.Adapter&lt;MuaAdapter.MuaViewHolder&gt; implements Filterable {
      private ArrayList&lt;MuaView&gt; mMuaView;
      private ArrayList&lt;MuaView&gt; mMuaViewFull;
      private OnItemClickListener mListener;
  
      public interface OnItemClickListener {
          void onItemClick(int position);
      }
  
      public void setOnItemClickListener(OnItemClickListener listener) {
          mListener = listener;
      }
  
      public static class MuaViewHolder extends RecyclerView.ViewHolder {
          public ImageButton mImageButton;
          public TextView mTextView1;
  
          public MuaViewHolder(@NonNull View itemView, final OnItemClickListener listener) {
              super(itemView);
              mImageButton = itemView.findViewById(R.id.mua_imageButton);
              mTextView1 = itemView.findViewById(R.id.mua_title);
  
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      if (listener != null) {
                          int position = getAdapterPosition();
                          if (position != RecyclerView.NO_POSITION) {
                              listener.onItemClick(position);
                          }
                      }
                  }
              });
  
              mImageButton.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      if (listener != null) {
                          int position = getAdapterPosition();
                          if (position != RecyclerView.NO_POSITION) {
                              listener.onItemClick(position);
                          }
                      }
                  }
              });
          }
      }
  
      public MuaAdapter(ArrayList&lt;MuaView&gt; muaView) {
         mMuaView = muaView;
      }
  
      @Override
      public MuaViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.mua_view, parent, false);
          MuaViewHolder mvh = new MuaViewHolder(v, mListener);
          return mvh;
      }
  
      @Override
      public void onBindViewHolder(@NonNull MuaViewHolder holder, int position) {
          MuaView currentView = mMuaView.get(position);
  
          holder.mImageButton.setImageResource(currentView.getImageResource());
          holder.mTextView1.setText(currentView.getText1());
      }
  
      @Override
      public int getItemCount() {
          return mMuaView.size();
      }
  
      public Filter getFilter() {
          return MuaFilter;
      }
  
      private Filter MuaFilter = new Filter() {
          @Override
          protected FilterResults performFiltering(CharSequence constraint) {
              List&lt;MuaView&gt; filteredList = new ArrayList&lt;&gt;();
  
              if (constraint == null || constraint.length() == 0) {
                  filteredList.addAll(mMuaViewFull);
              } else {
                  String filterPattern = constraint.toString().toLowerCase().trim();
  
                  for (MuaView item : mMuaViewFull) {
                      if (item.getText1().toLowerCase().contains(filterPattern)) {
                          filteredList.add(item);
                      }
                  }
              }
  
              FilterResults results = new FilterResults();
              results.values = filteredList;
  
              return results;
          }
  
          @Override
          protected void publishResults(CharSequence constraint, FilterResults results) {
              mMuaView.clear();
              mMuaView.addAll((ArrayList) results.values);
              notifyDataSetChanged();
  
          }
      };
  }
  </code></pre>
  
  <p>Here is my Activity:</p>
  
  <pre><code>    package android.com.example.weddingappfinale;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.inputmethod.EditorInfo;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.appcompat.widget.SearchView;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import java.util.ArrayList;
  
  import Adapters.MuaAdapter;
  import CustomerActivities.CustomerActivity;
  
  public class MuaActivity extends AppCompatActivity {
  
      private RecyclerView mRecyclerView;
      private MuaAdapter mAdapter;
      private RecyclerView.LayoutManager mLayoutManager;
      private ArrayList&lt;MuaView&gt; mMuaView = new ArrayList&lt;&gt;();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.mua_list);
  
          getSupportActionBar().setTitle("Make Up Artists");
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          ArrayList&lt;MuaView&gt; muaView = new ArrayList&lt;&gt;();
          muaView.add(new MuaView(R.drawable.mua_image, "Shima Matin Bridal Services"));
          muaView.add(new MuaView(R.drawable.photography_image, "Aake Up Artist Pte Ltd"));
          muaView.add(new MuaView(R.drawable.mua_image, "Lake Up Artist 3Pte Ltd"));
          muaView.add(new MuaView(R.drawable.mua_image, "f Up Artist Pte Ltd"));
  
          // ArrayList
  
          mRecyclerView = findViewById(R.id.recycler_view_list);
          mRecyclerView.setHasFixedSize(true);
          mLayoutManager = new LinearLayoutManager(this);
          mAdapter = new MuaAdapter(muaView);
  
          mRecyclerView.setLayoutManager(mLayoutManager);
          mRecyclerView.setAdapter(mAdapter);
  
          mAdapter.setOnItemClickListener(new MuaAdapter.OnItemClickListener() {
              @Override
              public void onItemClick(int position) {
                  Intent intent = new Intent(MuaActivity.this, CustomerActivity.class);
                  intent.putExtra("Customer's Details", mMuaView.get(position));
                  startActivity(intent);
              }
  
          });
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.search, menu);
  
          MenuItem searchItem = menu.findItem(R.id.action_search);
          SearchView searchView = (SearchView) searchItem.getActionView();
  
          searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
  
          searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
              @Override
              public boolean onQueryTextSubmit(String query) {
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String newText) {
                  mAdapter.getFilter().filter(newText);
                  return false;
              }
          });
          return true;
      }
  }
  </code></pre>
  
  <p>Here is my NewActivity: </p>
  
  <pre><code>    package CustomerActivities;
  
  import android.com.example.weddingappfinale.MuaView;
  import android.com.example.weddingappfinale.R;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.ImageButton;
  import android.widget.TextView;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  public class CustomerActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_customer);
          Intent intent = getIntent();
          MuaView muaView = intent.getParcelableExtra("Customer's Details");
  
          int imageRes = muaView.getImageResource();
          String line1 = muaView.getText1();
  
          ImageButton imageButton = findViewById(R.id.image_customer);
          imageButton.setImageResource(imageRes);
  
          TextView textView1 = findViewById(R.id.title_customer);
          textView1.setText(line1);
  
      }
  }
  </code></pre>
  
  <p>Here is my Parcelable: </p>
  
  <pre><code>    package android.com.example.weddingappfinale;
  
  import android.os.Parcel;
  import android.os.Parcelable;
  
  public class MuaView implements Parcelable {
      private int mImageResource;
      private String mText1;
  
      public MuaView(int imageResource, String text1) {
          mImageResource = imageResource;
          mText1 = text1;
      }
  
      protected MuaView(Parcel in) {
          mImageResource = in.readInt();
          mText1 = in.readString();
      }
  
      public static final Creator&lt;MuaView&gt; CREATOR = new Creator&lt;MuaView&gt;() {
          @Override
          public MuaView createFromParcel(Parcel in) {
              return new MuaView(in);
          }
  
          @Override
          public MuaView[] newArray(int size) {
              return new MuaView[size];
          }
      };
  
      public int getImageResource() {
          return mImageResource;
      }
  
      public String getText1() {
          return mText1;
      }
  
      @Override
      public int describeContents() {
          return 0;
      }
  
      @Override
      public void writeToParcel(Parcel dest, int flags) {
          dest.writeInt(mImageResource);
          dest.writeString(mText1);
      }
  }
  </code></pre>