【问题标题】:java.lang.IllegalStateException: get field slot from row 0 col 0 failedjava.lang.IllegalStateException:从行 0 col 0 获取字段槽失败
【发布时间】:2011-07-12 18:43:32
【问题描述】:

嘿,我正在尝试使用 AlphabetIndexer 实现 FastScroller。我正在列表视图中使用 500 个联系人对其进行测试。

当试图快速滚动它时,它会返回以下错误:

java.lang.IllegalStateException:从行 0 col 0 获取字段槽 失败

在这个方法中:

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

我认为:mAlphaIndexer.getPositionForSection(section) 正在返回“0”,因为我已经在这一行中放置了一个日志。并且错误出现在日志中,不再出现在返回中。

编辑:

LogCat 中显示的错误让我感到困惑和担心,因为我试图在列表视图中设置图像和文本以及复选框,因此对于每个视图,我都设置了一个图像和一个文本视图以及一个复选框。出现了这个错误:

ERROR/CursorWindow(24241): 需要增长: mSize = 1048576, size = 7702, freeSpace() = 3474, numRows = 135 错误/CursorWindow(24241): 不是 增长,因为已经有 135 行,最大大小 1048576 错误/光标(24241):在 134,5 处为 blob 分配 7702 字节失败

我猜这是因为它的大小,因为我正在测试在 ListView 中创建超过 1000 个项目。这可能是可能的错误吗?

它也显示在 LogCat 上:

ERROR/CursorWindow(24098):对字段槽 0,0 的错误请求。行数 = 0, numColumns = 0

这是我的 CursorAdapter 构造函数:

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);
            }
        }

游标既不是空也不是关闭(打印日志消息)。

FULL LOGCAT!粗线是错误出现的地方,也就是文章开头贴出的第一个方法。

07-14 09:40:49.042:错误/AndroidRuntime(24098):致命异常:主要 07-14 09:40:49.042: 错误/AndroidRuntime(24098): java.lang.IllegalStateException:从行 0 col 0 获取字段槽 07-14 09:40:49.042 失败:错误/AndroidRuntime(24098):在 android.database.CursorWindow.getLong_native(Native Method) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.database.CursorWindow.getLong(CursorWindow.java:380) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:108) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.database.AbstractCursor.moveToPosition(AbstractCursor.java:194) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.widget.AlphabetIndexer.getPositionForSection(AlphabetIndexer.java:202) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 com.test.myapplication.MyCursorAdapter.getPositionForSection(MyCursorAdapter.java:181) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.widget.FastScroller.scrollTo(FastScroller.java:324) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.widget.FastScroller.onTouchEvent(FastScroller.java:471) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.widget.AbsListView.onTouchEvent(AbsListView.java:2104) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.widget.ListView.onTouchEvent(ListView.java:3446) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.View.dispatchTouchEvent(View.java:3885) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.app.Activity.dispatchTouchEvent(Activity.java:2096) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.view.ViewRoot.handleMessage(ViewRoot.java:1878) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.os.Handler.dispatchMessage(Handler.java:99) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 android.os.Looper.loop(Looper.java:130) 07-14 09:40:49.042: 错误/AndroidRuntime(24098):在 android.app.ActivityThread.main(ActivityThread.java:3683) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 java.lang.reflect.Method.invokeNative(Native Method) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 java.lang.reflect.Method.invoke(Method.java:507) 07-14 09:40:49.042: 错误/AndroidRuntime(24098):在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-14 09:40:49.042:错误/AndroidRuntime(24098):在 dalvik.system.NativeStart.main(Native Method)

我该如何解决?谢谢!

【问题讨论】:

标签: android android-listview android-scrollbar


【解决方案1】:

发生错误是因为CursorWindow 类仅支持每次查询读取 1MB 的数据,因此我必须优化我的查询。

我只是在数据库中搜索数据,列表视图中的当前视图,所以我不需要查询所有数据。

【讨论】:

    【解决方案2】:

    您是否通过调用 setCursor(cursor) 设置光标?你的光标在这个时间点有效吗?

    【讨论】:

    • 准确地说:不为空且打开。检查 LogCat 以获取堆栈跟踪,它应该会告诉你更多关于为什么你会得到 IllegalStateException 和/或给你更多细节。
    • 调用 getPositionForSection 时,您的光标保留了多少条记录?也许您需要添加对空光标的检查,因此,按照文档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.,如果您的光标为空,您可能会返回 0。抱歉,我从未使用过 AlphabetIndexer。
    • 我已经设置了游标调用 setCursor 并且游标不是 null 也没有关闭。
    • 它不持有0,它持有游标中的所有行。只是为了检查,这是什么意思?调试/光标(24658):完成_program_and_get_row_count第64行
    • 对不起,不知道。您可以关注example,看看它是否适合您。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 2014-01-22
    • 2017-05-22
    相关资源
    最近更新 更多