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

  • SEARCH
  • Home
  • 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 8489273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:47:02+00:00 2026-06-10T21:47:02+00:00

I am using SectionIndexer for an ArrayAdapter and have fast scrolling enabled. Most lists

  • 0

I am using SectionIndexer for an ArrayAdapter and have fast scrolling enabled. Most lists work fine, but a couple crash at the same point and show the same type of log.

(Please note: The ListView is based on data inputted from a MySQL table. The list has about 2000 items. But the SQL in the list has a “where clause” where only 100-200 may show at a time. It appears the thumb scroller naturally scrolls the size of the 2000 items, and is not corresponding to this “where clause”. I don’t believe this is a PHP/MySQL issue but in my Android/Java.)

Here is log:

08-27 07:26:33.360: E/AndroidRuntime(9145): FATAL EXCEPTION: main
08-27 07:26:33.360: E/AndroidRuntime(9145): java.lang.ArrayIndexOutOfBoundsException: length=21; index=21-
08-27 07:26:33.360: E/AndroidRuntime(9145):     at com.---.---.ItemAdapter.getPositionForSection(ItemAdapter.java:57)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.widget.FastScroller.getThumbPositionForListPosition(FastScroller.java:650)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.widget.FastScroller.onScroll(FastScroller.java:458)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1325)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5067)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4205)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.view.Choreographer.doFrame(Choreographer.java:524)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.os.Handler.handleCallback(Handler.java:615)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.os.Looper.loop(Looper.java:137)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at android.app.ActivityThread.main(ActivityThread.java:4928)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at java.lang.reflect.Method.invokeNative(Native Method)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at java.lang.reflect.Method.invoke(Method.java:511)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
08-27 07:26:33.360: E/AndroidRuntime(9145):     at dalvik.system.NativeStart.main(Native Method)

Here is code by Line 57:

public int getPositionForSection(int section) {
    return alphaIndexer.get(sections[section]);
}

Also, here is more code in the adapter:

alphaIndexer = new HashMap<String, Integer>();
int size = objects.length;

for (int i = 0; i < size; i++) {

    ItemObject it = objects[i];
    String name = it.name;
    String s = name.substring(0, 1);
    s = s.toUpperCase();

    if (!alphaIndexer.containsKey(s)) {
        alphaIndexer.put(s, i);
    }
}

Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];

// sectionList.toArray(sections);

for (int i = 0; i < sectionList.size(); i++)
    sections[i] = sectionList.get(i);


public int getSectionForPosition(int position)

{
    int closestIndex = 0;
    int latestDelta = Integer.MAX_VALUE;

    for(int i=0; i < sections.length; i++) {

        Log.d("Sections Length: ", String.valueOf(sections.length));

        int current = alphaIndexer.get(sections[i]);
        if(current == position) {
            //If position matches an index, return it immediately
            return i;
        } else if(current < position) {
            //Check if this is closer than the last index we inspected
            int delta = position - current;
            if(delta < latestDelta) {
                closestIndex = i;
                latestDelta = delta;
            }
        }
    }

    return closestIndex;
}

public Object[] getSections() {
    return sections;
}
  • 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-06-10T21:47:04+00:00Added an answer on June 10, 2026 at 9:47 pm

    Her is my final code that worked:

        int size = objects.length;
    
    
            for (int i = 0; i < size; i++) {
    
                ItemObject it = objects[i];
                String name = it.name;
                String s = name.substring(0, 1);
                s = s.toUpperCase();
    
                if (!alphaIndexer.containsKey(s)) {
    
                    alphaIndexer.put(s, i);
                }
            }
    
            Set<String> sectionLetters = alphaIndexer.keySet();
            ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
            Collections.sort(sectionList);
            sections = new String[sectionList.size()];
            for (int i = 0; i < sectionList.size(); i++) {
                sections[i] = sectionList.get(i);
            }
    
        }
    
    
    public int getPositionForSection(int section) {
    
            int maxSize = sections.length - 1;
    
            if (section > maxSize) {
                return 0;
            } else {
    
                return alphaIndexer.get(sections[section]);
            }
        }
    
        public int getSectionForPosition(int position)
    
        {
            int closestIndex = 0;
            int latestDelta = Integer.MAX_VALUE;
    
            for (int i = 0; i < sections.length; i++) {
    
                int current = alphaIndexer.get(sections[i]);
                if (current == position) {
                    // If position matches an index, return it immediately
                    return i;
                } else if (current < position) {
                    // Check if this is closer than the last index we inspected
                    int delta = position - current;
                    if (delta < latestDelta) {
                        closestIndex = i;
                        latestDelta = delta;
                    }
                }
            }
    
            return closestIndex;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
I'm using implementation of SimpleCursorAdapter , which implements SectionIndexer . Here's part of it:
I am using sectionIndexTitlesForTableView to display index in a UITableView. It is working fine
I am sorting the UITableView by using a predicate with NSFetchedResultsController. But, when I
Ok Guys, here's the situation I have. I'm using a UITableViewController with Core Data.
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Core Data, I have a fetch request to fetch the minimum of a
Is it possible to use a SectionIndexer with a GridView in Android? Fast scroll

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.