gpt4 book ai didi

android - 非法状态异常 : get field slot from row 0 col -1 failed

转载 作者:行者123 更新时间:2023-11-29 22:29:18 26 4
gpt4 key购买 nike

int columnIndexFromAddrCountry;

public FavoritesActAdapter(Context context, int layout,
Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
gnCursor = c;

columnIndexFromAddrCountry =
c.getColumnIndex(DBAdapter.KEY_FROM_ADDR_COUNTRY);

}

@Override
public void bindView(View view, Context context, Cursor cursor) {
gnCursor = getCursor();

final String fromAddrCountry =
gnCursor.getString(columnIndexFromAddrCountry);

...

super.bindView(view, context, cursor);
}

为什么我会收到 IllegalStateException

IllegalStateException: get field slot from row 0 col -1 failed

这个异常是什么意思?此行抛出异常

final String fromAddrCountry = gnCursor.getString(columnIndexFromAddrCountry);

因为 columnIndexFromAddrCountry-1。该列存在,并且可以解析其他十个列。什么会导致这个问题?

提前致谢!

最佳答案

DBAdapter.KEY_FROM_ADDR_COUNTRY 设置为什么?

来自Cursor doc

public abstract int getColumnIndex (String columnName)

Since: API Level 1 Returns the zero-based index for the given column name, or -1 if the column doesn't exist. If you expect the column to exist use getColumnIndexOrThrow(String) instead, which will make the error more clear

因此您可以使用 getColumnIndexOrThrow(String) 获得更好的错误消息以帮助您进行调试。

关于android - 非法状态异常 : get field slot from row 0 col -1 failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4810048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com