无法从CursorWindow读取0行,列9 [英] Couldn't read row 0, col 9 from CursorWindow

查看:227
本文介绍了无法从CursorWindow读取0行,列9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的错误无法从CursorWindow读取0行,列9。确保光标从它访问数据之前正确初始化。另外两个人都能够无差错运行code,但我的机器上它扔了。我很困惑。这里是code,与SQLite的交易:
在此先感谢,对不起,有很多code的

 进口的java.util.ArrayList;
进口的java.util.List;
进口android.content.ContentValues​​;
进口android.content.Context;
进口android.database.Cursor;
进口android.database.sqlite.SQLiteDatabase;
进口android.database.sqlite.SQLiteOpenHelper;
进口android.util.Log;公共类FeedSQLiteHelper扩展SQLiteOpenHelper {//表名
公共静态最后弦乐TABLE_POSTS =意见;//表列名
公共静态最后弦乐COLUMN_ID =_id;
公共静态最后弦乐COLUMN_CAPTION =标题
公共静态最后弦乐COLUMN_NAME =名;
公共静态最后弦乐COLUMN_LIKE =喜欢;
公共静态最后弦乐COLUMN_DISLIKE =不喜欢;
公共静态最后弦乐COLUMN_COMMENTS =列;
公共静态最后弦乐COLUMN_ALL_COMMENTS =allComments;
公共静态最后弦乐COLUMN_PHOTO =照片;
公共静态最后弦乐COLUMN_CELEB =名人;
公共静态最后弦乐COLUMN_FID =facebook_id;
公共静态最后弦乐COLUMN_TIME =时间戳;私有静态最后弦乐DATABASE_NAME =commments.db;
私有静态最终诠释DATABASE_VERSION = 6;//数据库创建SQL语句
私有静态最后弦乐DATABASE_CREATE =CREATE TABLE
  + TABLE_POSTS +(+ COLUMN_ID
  +整数主键自动增量+ COLUMN_CAPTION
  +文本不为空,+ COLUMN_NAME +文本不为空,
  + COLUMN_LIKE +整数NOT NULL,+ COLUMN_DISLIKE +整数NOT NULL,
  + COLUMN_COMMENTS +整数NOT NULL,+ COLUMN_ALL_COMMENTS +文字
  + COLUMN_PHOTO +文字,+ COLUMN_FID +文字,+ COLUMN_TIME +长);;公共FeedSQLiteHelper(上下文的背景下){
超(背景下,DATABASE_NAME,空,DATABASE_VERSION);
}@覆盖
公共无效的onCreate(SQLiteDatabase数据库){
database.execSQL(DATABASE_CREATE);
}@覆盖
公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,诠释静态网页){
Log.w(FeedSQLiteHelper.class.getName(),
    + oldVersion +到从版本升级数据库
        + NEWVERSION +,这将摧毁所有旧数据);
如果(oldVersion 6;){
    最后弦乐ALTER_TBL =ALTER TABLE+ TABLE_POSTS +ADD COLUMN+ COLUMN_TIME +长;
    db.execSQL(ALTER_TBL);
}
}//添加新联系人
公共无效的addContact(FeedsModel接触){
SQLiteDatabase分贝= this.getWritableDatabase();ContentValues​​值=新ContentValues​​();
values​​.put(列,contact.getName());
values​​.put(COLUMN_CAPTION,contact.getDesc());
values​​.put(COLUMN_LIKE,contact.getUps());
values​​.put(COLUMN_DISLIKE,contact.getDowns());
values​​.put(COLUMN_COMMENTS,contact.getComments());
values​​.put(COLUMN_ALL_COMMENTS,contact.getAllComments());
values​​.put(COLUMN_PHOTO,contact.getImageId());
values​​.put(COLUMN_FID,contact.getFID());
values​​.put(COLUMN_TIME,contact.getTimestamp());//插入行
db.insert(TABLE_POSTS,空,价值);
db.close(); //关闭数据库连接
}//获取单触点
公共FeedsModel getContact(INT ID){
SQLiteDatabase分贝= this.getReadableDatabase();光标光标= db.query(TABLE_POSTS,新的String [] {COLUMN_ID,
        COLUMN_CAPTION,COLUMN_NAME,COLUMN_LIKE,COLUMN_DISLIKE,COLUMN_COMMENTS,COLUMN_ALL_COMMENTS,COLUMN_PHOTO,COLUMN_FID,COLUMN_TIME},COLUMN_ID +=?,
        新的String [] {将String.valueOf(ID)},NULL,NULL,NULL,NULL);
如果(指针!= NULL)
    cursor.moveToFirst();FeedsModel接触=新FeedsModel(
        的Integer.parseInt(cursor.getString(0)),
        cursor.getString(1),
        cursor.getString(2),
        的Integer.parseInt(cursor.getString(3)),
        的Integer.parseInt(cursor.getString(4)),
        的Integer.parseInt(cursor.getString(5)),
        cursor.getString(6),
        cursor.getString(7),
        cursor.getString(8),
        的Long.parseLong(cursor.getString(9)));//返回接触
返回接触;
}//过滤的'我'的选项新闻源
公开名单< FeedsModel> getMe(字符串我)
{
清单< FeedsModel> contactList =新的ArrayList< FeedsModel>();字符串selectQuery =SELECT * FROM+ TABLE_POSTS +WHERE+ COLUMN_FID +=+我。SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL);//通过所有行循环,并增加列表
如果(cursor.moveToFirst()){
    做{
        FeedsModel接触=新FeedsModel();
        contact.setId(的Integer.parseInt(cursor.getString(0)));
        contact.setDesc(cursor.getString(1));
        contact.setName(cursor.getString(2));
        contact.setUps(的Integer.parseInt(cursor.getString(3)));
        contact.setDowns(的Integer.parseInt(cursor.getString(4)));
        contact.setComments(的Integer.parseInt(cursor.getString(5)));
        contact.setAllComments(cursor.getString(6));
        contact.setImageId(cursor.getString(7));
        contact.setFID(cursor.getString(8));
        contact.setTimestamp(的Long.parseLong(cursor.getString(9)));
        //添加联系人名单
        contactList.add(接触);
    }而(cursor.moveToNext());
}//返回联系人列表
返回contactList;
}//过滤的'我'的选项新闻源
公开名单< FeedsModel> getMostRecent()
{
清单< FeedsModel> contactList =新的ArrayList< FeedsModel>();字符串selectQuery =SELECT * FROM+ TABLE_POSTS +ORDER BY+ COLUMN_TIME +DESC;SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL);//通过所有行循环,并增加列表
如果(cursor.moveToFirst()){
  做{
      FeedsModel接触=新FeedsModel();
      contact.setId(的Integer.parseInt(cursor.getString(0)));
      contact.setDesc(cursor.getString(1));
      contact.setName(cursor.getString(2));
      contact.setUps(的Integer.parseInt(cursor.getString(3)));
      contact.setDowns(的Integer.parseInt(cursor.getString(4)));
      contact.setComments(的Integer.parseInt(cursor.getString(5)));
      contact.setAllComments(cursor.getString(6));
      contact.setImageId(cursor.getString(7));
      contact.setFID(cursor.getString(8));
      contact.setTimestamp(的Long.parseLong(cursor.getString(9)));
      //添加联系人名单
      contactList.add(接触);
  }而(cursor.moveToNext());
}//返回联系人列表
返回contactList;
}//获取所有联系人
公开名单< FeedsModel> getAllContacts(){清单< FeedsModel> contactList =新的ArrayList< FeedsModel>();
//选择所有查询
字符串selectQuery =SELECT * FROM+ TABLE_POSTS;SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL);//通过所有行循环,并增加列表
如果(cursor.moveToFirst()){
    做{
        FeedsModel接触=新FeedsModel();
        contact.setId(的Integer.parseInt(cursor.getString(0)));
        contact.setDesc(cursor.getString(1));
        contact.setName(cursor.getString(2));
        contact.setUps(的Integer.parseInt(cursor.getString(3)));
        contact.setDowns(的Integer.parseInt(cursor.getString(4)));
        contact.setComments(的Integer.parseInt(cursor.getString(5)));
        contact.setAllComments(cursor.getString(6));
        contact.setImageId(cursor.getString(7));
        contact.setFID(cursor.getString(8));
        contact.setTimestamp(的Long.parseLong(cursor.getString(9)));
        //添加联系人名单
        contactList.add(接触);
    }而(cursor.moveToNext());
}//返回联系人列表
返回contactList;}//获取联系人计数
公众诠释getContactsCount(){字符串countQuery =SELECT * FROM+ TABLE_POSTS;
SQLiteDatabase分贝= this.getReadableDatabase();
光标光标= db.rawQuery(countQuery,NULL);
cursor.close();//返回计数
返回cursor.getCount();}
//更新单触点
公众诠释updateContact(FeedsModel接触){SQLiteDatabase分贝= this.getWritableDatabase();ContentValues​​值=新ContentValues​​();
values​​.put(列,contact.getName());
values​​.put(COLUMN_CAPTION,contact.getDesc());
values​​.put(COLUMN_LIKE,contact.getUps());
values​​.put(COLUMN_DISLIKE,contact.getDowns());
values​​.put(COLUMN_COMMENTS,contact.getComments());
values​​.put(COLUMN_ALL_COMMENTS,contact.getAllComments());
values​​.put(COLUMN_PHOTO,contact.getImageId());
values​​.put(COLUMN_FID,contact.getFID());
values​​.put(COLUMN_TIME,contact.getTimestamp());//更新行
返回db.update(TABLE_POSTS,价值观,COLUMN_ID +=?,
        新的String [] {将String.valueOf(contact.getId())});}//删除单个联系人
公共无效deleteContact(FeedsModel接触){SQLiteDatabase分贝= this.getWritableDatabase();
db.delete(TABLE_POSTS,COLUMN_ID +=?,
        新的String [] {将String.valueOf(contact.getId())});
db.close();}}

logcat的:

  E / CursorWindow(841):无法从其中有3行9列的CursorWindow读取0行,第9列。
D / AndroidRuntime(841):关闭VM
W / dalvikvm(841):主题ID = 1:螺纹未捕获的异常退出(组= 0x40a71930)
E / AndroidRuntime(841):致命异常:主要
E / AndroidRuntime(841):了java.lang.RuntimeException:无法启动活动ComponentInfo {edu.Drake.doppelganger / edu.Drake.doppelganger.MainActivity}:java.lang.IllegalStateException:无法读取0行,列9 CursorWindow。确保光标从它访问数据之前正确初始化。
E / AndroidRuntime(841):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E / AndroidRuntime(841):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E / AndroidRuntime(841):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
E / AndroidRuntime(841):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
E / AndroidRuntime(841):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(841):在android.os.Looper.loop(Looper.java:137)
E / AndroidRuntime(841):在android.app.ActivityThread.main(ActivityThread.java:5041)
E / AndroidRuntime(841):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(841):在java.lang.reflect.Method.invoke(Method.java:511)
E / AndroidRuntime(841):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
E / AndroidRuntime(841):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E / AndroidRuntime(841):在dalvik.system.NativeStart.main(本机方法)
E / AndroidRuntime(841):java.lang.IllegalStateException:产生的原因无法从CursorWindow读取0行,列9。确保光标从它访问数据之前正确初始化。
E / AndroidRuntime(841):在android.database.CursorWindow.nativeGetString(本机方法)
E / AndroidRuntime(841):在android.database.CursorWindow.getString(CursorWindow.java:434)
E / AndroidRuntime(841):在android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
E / AndroidRuntime(841):在edu.Drake.doppelganger.FeedSQLiteHelper.getAllContacts(FeedSQLiteHelper.java:198)
E / AndroidRuntime(841):在edu.Drake.doppelganger.FeedFragment.onActivityCreated(FeedFragment.java:65)
E / AndroidRuntime(841):在android.app.Fragment.performActivityCreated(Fragment.java:1703)
E / AndroidRuntime(841):在android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
E / AndroidRuntime(841):在android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
E / AndroidRuntime(841):在android.app.BackStackRecord.run(BackStackRecord.java:682)
E / AndroidRuntime(841):在android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
E / AndroidRuntime(841):在android.app.Activity.performStart(Activity.java:5113)
E / AndroidRuntime(841):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
E / AndroidRuntime(841):11 ...更多


解决方案

那是因为你尝试检查他们的可用数据没有之前得到的数据。

 如果(cursor.moveToFirst()){
    做{
        //你的内容
    }而(cursor.moveToNext());
}

此块更改为

 而(cursor.moveToNext()){
        //你的内容
}

筛选。

这肯定会帮助你。

I'm getting the error Couldn't read row 0, col 9 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. Two other people are able to run the code without error but on my machine it throws it. I'm very confused. Here is the code that deals with the SQLite: Thanks in advance, sorry there's a lot of code

import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class FeedSQLiteHelper extends SQLiteOpenHelper {

//Table Name
public static final String TABLE_POSTS = "comments";

//Table Column names
public static final String COLUMN_ID = "_id";
public static final String COLUMN_CAPTION = "caption";
public static final String COLUMN_NAME= "name";
public static final String COLUMN_LIKE="like";
public static final String COLUMN_DISLIKE="dislike";
public static final String COLUMN_COMMENTS = "columns";
public static final String COLUMN_ALL_COMMENTS = "allComments";
public static final String COLUMN_PHOTO = "photo";
public static final String COLUMN_CELEB = "celeb";
public static final String COLUMN_FID = "facebook_id";
public static final String COLUMN_TIME = "timestamp";

private static final String DATABASE_NAME = "commments.db";
private static final int DATABASE_VERSION = 6;

// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
  + TABLE_POSTS + "(" + COLUMN_ID
  + " integer primary key autoincrement, " + COLUMN_CAPTION
  + " text not null, " + COLUMN_NAME + " text not null, " 
  + COLUMN_LIKE + " integer not null, " + COLUMN_DISLIKE + " integer not null, "
  + COLUMN_COMMENTS + " integer not null, " + COLUMN_ALL_COMMENTS + " text, " 
  + COLUMN_PHOTO + " text, " + COLUMN_FID + " text, " + COLUMN_TIME + " long);";

public FeedSQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(FeedSQLiteHelper.class.getName(),
    "Upgrading database from version " + oldVersion + " to "
        + newVersion + ", which will destroy all old data");
if(oldVersion <6) {
    final String ALTER_TBL = "ALTER TABLE " + TABLE_POSTS + " ADD COLUMN " + COLUMN_TIME     + " long;";
    db.execSQL(ALTER_TBL);
}
}

//Adding new contact
public void addContact(FeedsModel contact) {
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(COLUMN_NAME, contact.getName());
values.put(COLUMN_CAPTION, contact.getDesc());
values.put(COLUMN_LIKE, contact.getUps());
values.put(COLUMN_DISLIKE, contact.getDowns());
values.put(COLUMN_COMMENTS, contact.getComments());
values.put(COLUMN_ALL_COMMENTS, contact.getAllComments());
values.put(COLUMN_PHOTO, contact.getImageId());
values.put(COLUMN_FID, contact.getFID());
values.put(COLUMN_TIME, contact.getTimestamp());

// Inserting Row
db.insert(TABLE_POSTS, null, values);
db.close(); // Closing database connection
}

//Getting single contact
public FeedsModel getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(TABLE_POSTS, new String[] { COLUMN_ID,
        COLUMN_CAPTION, COLUMN_NAME, COLUMN_LIKE, COLUMN_DISLIKE, COLUMN_COMMENTS,      COLUMN_ALL_COMMENTS, COLUMN_PHOTO, COLUMN_FID, COLUMN_TIME }, COLUMN_ID + "=?",
        new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
    cursor.moveToFirst();

FeedsModel contact = new FeedsModel(
        Integer.parseInt(cursor.getString(0)), 
        cursor.getString(1), 
        cursor.getString(2), 
        Integer.parseInt(cursor.getString(3)), 
        Integer.parseInt(cursor.getString(4)),
        Integer.parseInt(cursor.getString(5)),
        cursor.getString(6),
        cursor.getString(7),
        cursor.getString(8),
        Long.parseLong(cursor.getString(9)));

// return contact
return contact;
}

//filters the news feed for the 'Me' option
public List<FeedsModel> getMe(String me)
{
List<FeedsModel> contactList = new ArrayList<FeedsModel>();

String selectQuery = "SELECT * FROM " + TABLE_POSTS + " WHERE " + COLUMN_FID + "= "+ me;

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list
if (cursor.moveToFirst()) {
    do {
        FeedsModel contact = new FeedsModel();
        contact.setId(Integer.parseInt(cursor.getString(0)));
        contact.setDesc(cursor.getString(1));
        contact.setName(cursor.getString(2));
        contact.setUps(Integer.parseInt(cursor.getString(3)));
        contact.setDowns(Integer.parseInt(cursor.getString(4)));
        contact.setComments(Integer.parseInt(cursor.getString(5)));
        contact.setAllComments(cursor.getString(6));
        contact.setImageId(cursor.getString(7));
        contact.setFID(cursor.getString(8));
        contact.setTimestamp(Long.parseLong(cursor.getString(9)));
        // Adding contact to list
        contactList.add(contact);
    } while (cursor.moveToNext());
}

// return contact list
return contactList;
}

//filters the news feed for the 'Me' option
public List<FeedsModel> getMostRecent()
{
List<FeedsModel> contactList = new ArrayList<FeedsModel>();

String selectQuery = "SELECT * FROM " + TABLE_POSTS + " ORDER BY " + COLUMN_TIME + " DESC";

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list
if (cursor.moveToFirst()) {
  do {
      FeedsModel contact = new FeedsModel();
      contact.setId(Integer.parseInt(cursor.getString(0)));
      contact.setDesc(cursor.getString(1));
      contact.setName(cursor.getString(2));
      contact.setUps(Integer.parseInt(cursor.getString(3)));
      contact.setDowns(Integer.parseInt(cursor.getString(4)));
      contact.setComments(Integer.parseInt(cursor.getString(5)));
      contact.setAllComments(cursor.getString(6));
      contact.setImageId(cursor.getString(7));
      contact.setFID(cursor.getString(8));
      contact.setTimestamp(Long.parseLong(cursor.getString(9)));
      // Adding contact to list
      contactList.add(contact);
  } while (cursor.moveToNext());
}

// return contact list
return contactList;
}

//Getting All Contacts
public List<FeedsModel> getAllContacts() {

List<FeedsModel> contactList = new ArrayList<FeedsModel>();
// Select All Query
String selectQuery = "SELECT  * FROM " + TABLE_POSTS;

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list
if (cursor.moveToFirst()) {
    do {
        FeedsModel contact = new FeedsModel();
        contact.setId(Integer.parseInt(cursor.getString(0)));
        contact.setDesc(cursor.getString(1));
        contact.setName(cursor.getString(2));
        contact.setUps(Integer.parseInt(cursor.getString(3)));
        contact.setDowns(Integer.parseInt(cursor.getString(4)));
        contact.setComments(Integer.parseInt(cursor.getString(5)));
        contact.setAllComments(cursor.getString(6));
        contact.setImageId(cursor.getString(7));
        contact.setFID(cursor.getString(8));
        contact.setTimestamp(Long.parseLong(cursor.getString(9)));
        // Adding contact to list
        contactList.add(contact);
    } while (cursor.moveToNext());
}

// return contact list
return contactList;

}

//Getting contacts Count
public int getContactsCount() {

String countQuery = "SELECT  * FROM " + TABLE_POSTS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();

// return count
return cursor.getCount();

}
//Updating single contact
public int updateContact(FeedsModel contact) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(COLUMN_NAME, contact.getName());
values.put(COLUMN_CAPTION, contact.getDesc());
values.put(COLUMN_LIKE, contact.getUps());
values.put(COLUMN_DISLIKE, contact.getDowns());
values.put(COLUMN_COMMENTS, contact.getComments());
values.put(COLUMN_ALL_COMMENTS, contact.getAllComments());
values.put(COLUMN_PHOTO, contact.getImageId());
values.put(COLUMN_FID, contact.getFID());
values.put(COLUMN_TIME, contact.getTimestamp());

// updating row
return db.update(TABLE_POSTS, values, COLUMN_ID + " = ?",
        new String[] { String.valueOf(contact.getId()) });

}

//Deleting single contact
public void deleteContact(FeedsModel contact) {

SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_POSTS, COLUMN_ID + " = ?",
        new String[] { String.valueOf(contact.getId()) });
db.close();

}

} 

Logcat:

E/CursorWindow(841): Failed to read row 0, column 9 from a CursorWindow which has 3 rows, 9 columns.
D/AndroidRuntime(841): Shutting down VM
W/dalvikvm(841): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
E/AndroidRuntime(841): FATAL EXCEPTION: main
E/AndroidRuntime(841): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.Drake.doppelganger/edu.Drake.doppelganger.MainActivity}: java.lang.IllegalStateException: Couldn't read row 0, col 9 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
E/AndroidRuntime(841):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E/AndroidRuntime(841):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(841):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(841):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(841):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(841):  at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(841):  at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(841):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(841):  at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(841):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(841):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(841):  at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(841): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 9 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
E/AndroidRuntime(841):  at android.database.CursorWindow.nativeGetString(Native Method)
E/AndroidRuntime(841):  at android.database.CursorWindow.getString(CursorWindow.java:434)
E/AndroidRuntime(841):  at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
E/AndroidRuntime(841):  at edu.Drake.doppelganger.FeedSQLiteHelper.getAllContacts(FeedSQLiteHelper.java:198)
E/AndroidRuntime(841):  at edu.Drake.doppelganger.FeedFragment.onActivityCreated(FeedFragment.java:65)
E/AndroidRuntime(841):  at android.app.Fragment.performActivityCreated(Fragment.java:1703)
E/AndroidRuntime(841):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
E/AndroidRuntime(841):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
E/AndroidRuntime(841):  at android.app.BackStackRecord.run(BackStackRecord.java:682)
E/AndroidRuntime(841):  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
E/AndroidRuntime(841):  at android.app.Activity.performStart(Activity.java:5113)
E/AndroidRuntime(841):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
E/AndroidRuntime(841):  ... 11 more

解决方案

it is because you try to get the data before checking their is data available or not.

if (cursor.moveToFirst()) {
    do {
        // your content
    } while (cursor.moveToNext());
}

Change this block to

while (cursor.moveToNext()) {
        // your content
}

Like this.

Surely this will help you.

这篇关于无法从CursorWindow读取0行,列9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆