我尝试使用上下文菜单从listview中删除数据,得到了java.lang.IllegalStateException:Could not read row 0,col 2 from CursorWindow。在从游标访问数据之前,请确保游标已正确初始化。
public List<AssignmentRecord> getAllAssignment(){
List<AssignmentRecord> records = new ArrayList<AssignmentRecord>();
Cursor cursor = database.query(AssigmentContract.Assigment.TABLE_NAME, allColumn , null,
null, null, null, null);
cursor.moveToFirst();
while(!cursor.isAfterLast()){
AssignmentRecord assignmentRecord = new AssignmentRecord();
assignmentRecord.setAssname(cursor.getString(0));
assignmentRecord.setAssTime(cursor.getString(1));
assignmentRecord.setAssID(cursor.getString(2));
records.add(assignmentRecord);
cursor.moveToNext();
}
第一行错误AssignmentRecord.SetAssid(Cursor.GetString(2));
dbcon.open();
List<AssignmentRecord> records = dbcon.getAllAssignment();
dbcon.close();
第二个错误是List records=dbcon.getallassignment();
private static final String SQL_CREATE_ENTRIES = "CREATE TABLE "
+ AssigmentContract.Assigment.TABLE_NAME +
"(" + AssigmentContract.Assigment.COLUMN_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " +
AssigmentContract.Assigment.COLUMN_ASS + " TEXT," +
AssigmentContract.Assigment.COLUMN_ASSDATE+ " TEXT)";
public final class AssigmentContract {
public AssigmentContract(){}
public static abstract class Assigment implements BaseColumns{
public static final String TABLE_NAME ="AssignmentV2";
public static final String COLUMN_ASS ="AssignmentTitle";
public static final String COLUMN_ASSDATE ="AssignmentDate";
public static final String COLUMN_ID ="AssignmentID";
}
}
my.com.chyi.schedulev2 E/CursorWindow﹕ Failed to read row 0, column 2 from a CursorWindow which has 1 rows, 2 columns.
my.com.chyi.schedulev2 D/AndroidRuntime﹕ Shutting down VM
my.com.chyi.schedulev2 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x9e4f5908)
/my.com.chyi.schedulev2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.com.chyi.schedulev2/my.com.chyi.schedulev2.assigmentActivity}: java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:434)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at my.com.chyi.schedulev2.SQLController.getAllAssignment(SQLController.java:102)
at my.com.chyi.schedulev2.assigmentActivity.onCreate(assigmentActivity.java:73)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
Android.app.ActivityThread.HandleLaunchActivity(ActivityThread.java:2230,Android.app.ActivityThread.Access$600(ActivityThread.java:141),Android.app.ActivityThread.Access$H.HandleMessage(ActivityThread.java:1234,Android.os.Handler.DispatchMessage(ActivityThread.java:99),Android.os.Looper.Loop(ActivityThread.java:137),Android.app.ActivityThread.Main(
试试这个,
while(!cursor.isAfterLast()){
AssignmentRecord assignmentRecord = new AssignmentRecord();
assignmentRecord.setAssname(cursor.getString(cursor.getColumnIndex("your_respective_column_name));
assignmentRecord.setAssTime(cursor.getString(cursor.getColumnIndex("your_respective_column_name)));
assignmentRecord.setAssID(cursor.getString(cursor.getColumnIndex("your_respective_column_name)));
records.add(assignmentRecord);
cursor.moveToNext();
我已经演示了哈里建议你做的事。在这里,用您为试图检索的列给定的值替换您各自的列名。对于ex:当您试图获取AssId的值时,它将是_id或其他东西。希望这对你有帮助。
问题内容: 使用数据库时出现问题。当我运行SQLView.java时,出现一个致命异常: 希望有人可以帮助我。我将发布所有与数据库相关的代码。当您需要更多信息时,请告诉我,不要犹豫,索取更多信息! 我认为我的专栏有问题,无法找出原因。 另外,我已经阅读了该网站上的所有相关问题,但是我找不到应该在何处声明我的列以及要添加/更改的内容。有人知道怎么做吗?:) 首先:我的数据库类: SQLite类,用于
我正在开发一个应用程序,下载一些文件,并将其文本保存在文件内容字段中的数据库中。文件大小可以从一些KB到10 MB不等。该应用程序在保存时适用于所有尺寸。在长文件内容记录上使用select语句时出现问题。它给 java.lang.非法状态异常:无法从CursorWindow读取行0, col0 获取这样的行时。字段内容大小是否有限制?如果是这样,那么为什么它让我们在检索时保存并给出错误呢?这是我截
问题内容: 我正在创建一个使用SQLiteDatabase来存储项目的应用程序。但是,从数据库中填充数据时出现错误,应用崩溃。 这是我的数据库- Note.java- NotesDatabase.java- 这是LogCat错误日志- 请帮助我找出我的代码出了什么问题。提前致谢!! 问题答案: 您的主题行具有误导性。您的堆栈跟踪中的异常说 这实际上意味着无法在中找到指定的列,并且-1作为列索引返回
TextWatcher代码: LogCat错误:
日志猫 由:java.lang.IllegalStateException引起:无法从CursorWindow读取第0行,第5行。在从中访问数据之前,请确保光标已正确初始化。在Android.database.cursorwindow.nativegetString(本机方法)在Android.database.cursorwindow.getString(cursorwindow.java:46