当我在手机中运行当前的Android项目时,尝试执行此代码片段:
Intent intent = getIntent();
String itemA = intent.getStringExtra("itemA");
String itemB = intent.getStringExtra("itemB");
Cursor u = usuario.findByFields(new String[] {"nome", "sobrenome"}, new String[] {itemA, itemB});
startManagingCursor(u);
if(u.getCount() > 0) {
if(u.getColumnCount() > 0) {
u.moveToFirst();
fillForm(u.getString(1), u.getString(2), u.getString(3), u.getString(4), u.getString(5), u.getString(6));
}
}
我收到此错误:
E/AndroidRuntime(12620): FATAL EXCEPTION: main
E/AndroidRuntime(12620): Process: org.hello, PID: 12620
E/AndroidRuntime(12620): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.hello/org.hello.FormEditItemActivity}: java.lang.IllegalStateException: Couldn't read row 0, col 6 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
E/AndroidRuntime(12620): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
E/AndroidRuntime(12620): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
E/AndroidRuntime(12620): at android.app.ActivityThread.access$800(ActivityThread.java:139)
E/AndroidRuntime(12620): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
E/AndroidRuntime(12620): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(12620): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(12620): at android.app.ActivityThread.main(ActivityThread.java:5086)
E/AndroidRuntime(12620): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(12620): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(12620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime(12620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime(12620): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(12620): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 6 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
E/AndroidRuntime(12620): at android.database.CursorWindow.nativeGetString(Native Method)
E/AndroidRuntime(12620): at android.database.CursorWindow.getString(CursorWindow.java:434)
E/AndroidRuntime(12620): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
E/AndroidRuntime(12620): at org.hello.FormEditItemActivity.onCreate(FormEditItemActivity.java:52)
E/AndroidRuntime(12620): at android.app.Activity.performCreate(Activity.java:5248)
E/AndroidRuntime(12620): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
E/AndroidRuntime(12620): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
E/AndroidRuntime(12620): ... 11 more
W/ActivityManager( 916): Force finishing activity org.hello/.FormEditItemActivity
W/ActivityManager( 916): Force finishing activity org.hello/.HelloActivity
任何人都可以看到错误的是什么?因为我无法弄清楚我在这里缺少什么。
答案 0 :(得分:0)
游标的索引是基于零的。
所以你应该使用u.getString(0).... u.getString(5)