Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:13:22+00:00 2026-05-23T13:13:22+00:00

Hi I am using a custom Adapter class as an adapter in listview when

  • 0

Hi I am using a custom Adapter class as an adapter in listview when I scroll the list after around 5-6 positions my application force closes on looking at the LogCat output I get

07-06 04:48:36.635: ERROR/AndroidRuntime(1884): FATAL EXCEPTION: main<br>
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):java.lang.ArrayIndexOutOfBoundsException               
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at         android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:4528)<br>
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.widget.ListView.scrollListItemsBy(ListView.java:2863)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.widget.ListView.arrowScrollImpl(ListView.java:2340)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.widget.ListView.arrowScroll(ListView.java:2287)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.widget.ListView.commonKey(ListView.java:2089)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.widget.ListView.onKeyDown(ListView.java:2036)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.KeyEvent.dispatch(KeyEvent.java:1256)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.View.dispatchKeyEvent(View.java:3855)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:787)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.widget.ListView.dispatchKeyEvent(ListView.java:2021)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.os.Looper.loop(Looper.java:123)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at android.app.ActivityThread.main(ActivityThread.java:3647)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at java.lang.reflect.Method.invokeNative(Native Method)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at java.lang.reflect.Method.invoke(Method.java:507)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-06 04:48:36.635: ERROR/AndroidRuntime(1884):     at dalvik.system.NativeStart.main(Native Method)

The code for my class is

     import android.app.AlertDialog;
     import android.content.Context;
     import android.view.LayoutInflater;
     import android.view.View;
     import android.view.ViewGroup;
     import android.view.View.OnClickListener;
     import android.widget.ArrayAdapter;
     import android.widget.ImageButton;
     import android.widget.ImageView;
     import android.widget.TextView;
     import android.widget.Toast;

     public class MyClassAdapter extends ArrayAdapter<String> {
 private ArrayList<String> values;
 private LayoutInflater inflator;
     private Context mContext;
 static class ViewHolder {
    public TextView text;
    public TextView gender;
    public TextView distance;
    public ImageView image;
        public ImageView onlineicon;
        public TextView uid;
}

public MyClassAdapter(Context context, ArrayList<String> values) {
    super(context, R.id.TextView01, values);
    this.values = new ArrayList<String>(values);
    inflator = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   mContext=context;
}

@Override
public int getViewTypeCount() {
    return 2;
}

@Override
public int getItemViewType(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = convertView;

    if (rowView == null) {
        rowView = inflator.inflate(R.layout.row_odd, null);
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.text = (TextView) rowView.findViewById(R.id.TextView01);
        viewHolder.gender=(TextView)rowView.findViewById(R.id.textView2);
        viewHolder.distance=(TextView)rowView.findViewById(R.id.textView1);
        viewHolder.image = (ImageView) rowView
                .findViewById(R.id.ImageView01);
        viewHolder.onlineicon=(ImageView)rowView.findViewById(R.id.imageView1);
        viewHolder.uid=(TextView)rowView.findViewById(R.id.textView3);
        rowView.setTag(viewHolder);
    }
    ViewHolder holder = (ViewHolder) rowView.getTag();
    String Check=values.get(position);

        holder.text.setText(check);
    holder.gender.setText("kss");
    holder.distance.setText("");
    holder.uid.setText("XYz");
    return rowView;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:13:22+00:00Added an answer on May 23, 2026 at 1:13 pm

    In getViewTypeCount your adapter is reporting that there are exactly 2 item view types, but your getItemViewType method returns the position which is not restricted to the range [0, 2) unless you only have a maximum of 2 items in your list. Whenever ListView asks for a position beyond the second, your adapter reports an invalid view type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using an array list, a listView, and a custom simple adapter in
friends, i am using following custom adapter to show textview and checboxes in listview.
I have created a custom Base Adapter class, to populate a list view with
I have List of items. I'm using custom adapter (Android 1.5). Everything works perfectly,
I use a custom list adapter and ArrayList for my ListView. This solution was
I have three textviews in a row of a listview using custom adapter and
I'm trying to delete items from a ListView using a custom adapter which extends
I am using a ListView with a custom adapter for displaying items as pairs
I'm using a custom-built inhouse application that generates a standard set of reports on
We are using a custom FTP application (which encrypts the files) for secure transfers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.