count不会将光标移动到android中的位置1

时间:2011-08-24 03:13:31

标签: java android sqlite android-layout android-emulator

我正在开发一个Android应用程序,我在其中填充SQLite数据库中的微调器。 它有一个简单的表单,其数据保存在数据库表中。我保留了一个选项,允许用户自己提交表单。

因此,要获取已保存表单的ID,我将光标移动到最后一个位置。当我尝试加载保存的表单时,我收到此错误。

08-24 08:32:47.780: ERROR/AndroidRuntime(3988): FATAL EXCEPTION: main
08-24 08:32:47.780: ERROR/AndroidRuntime(3988): java.lang.IllegalStateException: couldn't move cursor to position 1
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.CursorAdapter.getView(CursorAdapter.java:178)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.Spinner.makeAndAddView(Spinner.java:192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.Spinner.layout(Spinner.java:151)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.Spinner.onLayout(Spinner.java:115)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1049)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.ScrollView.onLayout(ScrollView.java:1304)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047) 
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.View.layout(View.java:7192)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1141)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1860)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.os.Looper.loop(Looper.java:123)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at android.app.ActivityThread.main(ActivityThread.java:3835)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at java.lang.reflect.Method.invoke(Method.java:507)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-24 08:32:47.780: ERROR/AndroidRuntime(3988):     at dalvik.system.NativeStart.main(Native Method)

它没有指向我文件中的任何特定错误。 我移动到最后位置,它正在工作。所以我一旦完成从光标获取数据,我就会将其移回第一个位置。仍然没有工作

第一个表单下面的所有表单都是工作的其余表单不起作用:(

请帮助我

您诚挚的, ChinniKrishna Kothapalli。

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

if (cursor != null) 
{
    try {
       while (cursor.moveToNext()) 
       {
        i = 0;
            // System.out.println(" =======> From DBConnect, Header => "+cursor.getString(1));
       }
    } catch (Exception e) {
       Log.d("DB_SELECT_BUSINESS_EXCEPTION", "" + e.getMessage());
    } finally {
       cursor.close();
    }
}

答案 1 :(得分:0)

尝试使用

 if(cursor.moveToLast()){
                        }