12-02 16:58:34.770: DEBUG/AndroidRuntime(9337): Shutting down VM
12-02 16:58:34.770: WARN/dalvikvm(9337): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337): FATAL EXCEPTION: main
12-02 16:58:34.770: ERROR/AndroidRuntime(9337): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.sql/com.android.sql.SQLite4}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.os.Looper.loop(Looper.java:144)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.app.ActivityThread.main(ActivityThread.java:4937)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at java.lang.reflect.Method.invokeNative(Native Method)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at java.lang.reflect.Method.invoke(Method.java:521)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at dalvik.system.NativeStart.main(Native Method)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at com.android.sql.SQLite4.onCreate(SQLite4.java:54)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
12-02 16:58:34.770: ERROR/AndroidRuntime(9337):     ... 11 more
12-02 16:58:34.780: WARN/ActivityManager(98):   Force finishing activity com.android.sql/.SQLite4
12-02 16:58:34.820: WARN/Addapter(204): info.icon:2130837537

解决方案 »

  1.   

    android 的报错信息都是什么意思啊
      

  2.   

    cursor = db.query("countrycode",
    new String[] {"country","code",}, "id = ?",
    new String[]{"1"}, null, null, null);
    cursor.moveToFirst();
    country2 = cursor.getString(0);
    code2 = cursor.getString(1);
      

  3.   

    你的代码:
    cursor = db.query("countrycode",new String[] {"country","code",}, "id = ?",new String[]{"1"}, null, null, null);
    cursor.moveToFirst();
    country2 = cursor.getString(0);
    code2 = cursor.getString(1);
    这些代码基本上都有固定格式,建议改成:
    cursor = db.query("countrycode",new String[] {"country","code",}, "id = ?",new String[]{"1"}, null, null, null);
    if((cursor != null)&&(cursor.getCount>0) ){
    cursor.moveToFirst();
    country2 = cursor.getString(0);
    code2 = cursor.getString(1);
    }
      

  4.   

    报错的信息这句是最重要的:Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
    首先是游标越界,其次是size=0,那么你想获取0索引下标的值,就会出现越界错误
    为什么会出现这种情况呢,因为你要获取的数据库表中该列的行数恰好为0,也不是不存在,就是没有记录,但是该列存在。
    为了避免这样的错误,你可以先通过cursor.getCount()判断该列对应的行数是否为0,如果不为0,则继续
      

  5.   

    MyHelper helper;
    SQLiteDatabase db;helper = new MyHelper(this, DB_NAME, null, VERSION);db = helper.getWritableDatabase();sql="insert into countrycode(country,code) values ('独行','Alone')";
    db.execSQL(sql);这个不能插入吗????