0

Hey I'm trying to implement an FastScroller with AlphabetIndexer. And I'm testing it with 500 contacts in a list view.

And when trying to fast scroll it, it returns the folowing error:

java.lang.IllegalStateException: get field slot from row 0 col 0 failed

In this method:

@Override
public int getPositionForSection(int section)
{
    return mAlphaIndexer.getPositionForSection(section);
}

I suposse this: mAlphaIndexer.getPositionForSection(section) is returning '0', due to the fact I've put a Log with this line. And the error showed up in the Log not in the returnment anymore.

Edit:

There is an error showing in LogCat that made me confused and worried, because I'm trying to set images and text and checkbox in a listview, so for each view I set an image and a text view and a checkbox. And this error came up:

ERROR/CursorWindow(24241): need to grow: mSize = 1048576, size = 7702, freeSpace() = 3474, numRows = 135 ERROR/CursorWindow(24241): not growing since there are already 135 row(s), max size 1048576 ERROR/Cursor(24241): Failed allocating 7702 bytes for blob at 134,5

I guess this is because of the size of it, due to the fact that I'm testing creating more then 1000 items in the ListView. Can that be the possible error?

it also shows on LogCat:

ERROR/CursorWindow(24098): Bad request for field slot 0,0. numRows = 0, numColumns = 0

Here is my CursorAdapter Constructor:

public MyCursorAdapter(Context context, Cursor cursor, ArrayList<Integer> ids) 
        {
            super(context, cursor);
            try
            {           

                mAlphaIndexer = new AlphabetIndexer(cursor, cursor.getColumnIndexOrThrow("Name")," ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            mAlphaIndexer.setCursor(cursor);
            if(!cursor.isClosed() && cursor != null)
            {
                Log.i("MyCursorAdapter", "Cursor opened and not null " + cursor);
            }
            this.mSelectedIndividuals = ids;
            catch(IllegalArgumentException ex)
            {
                Log.e("MyCursorAdapter", "Error: " + ex);
            }
        }

The cursor isnt null neither closed (The log message is printed).

FULL LOGCAT! The bold line is where the error shows up, that is the first method posted in the beggining of the post.

07-14 09:40:49.042: ERROR/AndroidRuntime(24098): FATAL EXCEPTION: main 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): java.lang.IllegalStateException: get field slot from row 0 col 0 failed 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.database.CursorWindow.getLong_native(Native Method) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.database.CursorWindow.getLong(CursorWindow.java:380) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:108) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:194) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.widget.AlphabetIndexer.getPositionForSection(AlphabetIndexer.java:202) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at com.test.myapplication.MyCursorAdapter.getPositionForSection(MyCursorAdapter.java:181) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.widget.FastScroller.scrollTo(FastScroller.java:324) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.widget.FastScroller.onTouchEvent(FastScroller.java:471) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2104) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.widget.ListView.onTouchEvent(ListView.java:3446) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.View.dispatchTouchEvent(View.java:3885) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.app.Activity.dispatchTouchEvent(Activity.java:2096) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.os.Handler.dispatchMessage(Handler.java:99) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.os.Looper.loop(Looper.java:130) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at android.app.ActivityThread.main(ActivityThread.java:3683) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at java.lang.reflect.Method.invokeNative(Native Method) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at java.lang.reflect.Method.invoke(Method.java:507) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-14 09:40:49.042: ERROR/AndroidRuntime(24098): at dalvik.system.NativeStart.main(Native Method)

How can I solve it? Thanks!

rogcg
  • 10,451
  • 20
  • 91
  • 133
  • It may help you: http://stackoverflow.com/questions/9029668/android-sqlite-cursor-getcolumnindex-is-case-sensitive – Yaqub Ahmad Jan 27 '12 at 08:02

2 Answers2

11

The error was happening because the CursorWindow class only supports reading 1MB of data per query, so I had to optimize my query.

I only was searching for the data in the database, for the current views in the listview, so I wouldnt need to query all of the data.

rogcg
  • 10,451
  • 20
  • 91
  • 133
0

Have you set cursor by calling setCursor(cursor) ? Is your cursor valid at this point in time?

Audrius
  • 2,836
  • 1
  • 26
  • 35
  • Precisely: not null and open. Check LogCat for a stacktrace, it should tell you more about why you get IllegalStateException and/or give you more details. – Audrius Jul 14 '11 at 12:19
  • How many records does your cursor hold when getPositionForSection gets called? Maybe you need to add a check for empty cursor, so, following documentation `the row index of the first occurrence, or the nearest next letter. For instance, if searching for "T" and no "T" is found, then the first row starting with "U" or any higher letter is returned. If there is no data following "T" at all, then the list size is returned.`, you may return 0 if your cursor is empty. Sorry I have never used AlphabetIndexer. – Audrius Jul 14 '11 at 12:59
  • I've set the cursor calling setCursor and the cursor isnt null neither closed. – rogcg Jul 14 '11 at 13:01
  • its not holding 0, its holding all th rows in the cursor. Just for check, what does this means? DEBUG/Cursor(24658): finish_program_and_get_row_count row 64 – rogcg Jul 14 '11 at 13:11
  • Sorry, have no idea. You can follow the [example](http://www.anddev.org/tutusing_alphabetindexer_for_fastscrolling_listview-t10282.html) and see it it works for you. – Audrius Jul 14 '11 at 13:24
  • For that error ERROR/CursorWindow(24241): need to grow: mSize = 1048576, size = 7702, freeSpace() = 3474, numRows = 135 ERROR/CursorWindow(24241): not growing since there are already 135 row(s), max size 1048576 ERROR/Cursor(24241): Failed allocating 7702 bytes for blob at 134,5 -- I've seen this link: http://stackoverflow.com/questions/4561085/android-sql-lite-fail-to-grow – rogcg Jul 14 '11 at 13:27