2

我创建了一个包含 7 列和 1 行的表。但是我无法使用如下代码检索存储在 sqlite 中的数据。以前它在有 6 列时起作用..但是今天当我输入带有 bname 的新列时错误显示创建表::

@Override
    public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE " + DATABASE_TABLE+"("+KEY_BBOOKID+" varchar(15),"+KEY_DESC+" text(1500),"+KEY_URL1+" BLOB,"+KEY_URL2+" BLOB,"+KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT ,"+KEY_NAME+" varchar(150),"+KEY_BNAME+" varchar(150))");
}

在数据库类

我正在使用检索数据

private void getDataAndPopulate() 
{
    mapId = new ArrayList<String>();
    mapName=new ArrayList<String>();
    mapBookId = new ArrayList<String>();
    mapDesc = new ArrayList<String>();
    map1 = new ArrayList<byte[]>();
    map2 = new ArrayList<byte[]>();
    Cursor cursor = getEvents("pagess");
    while (cursor.moveToNext())
    {
         String temp_bookid = cursor.getString(0);
         String temp_desc=cursor.getString(1);
         byte[] temp_image1 = cursor.getBlob(2);
         byte[] temp_image2 = cursor.getBlob(3);
         String temp_id=cursor.getString(4);
         String temp_name = cursor.getString(5);
         String temp_bname=cursor.getString(6);
         mapId.add(temp_id);
         mapBname.add(temp_bname);
         mapBookId.add(temp_bookid);
         mapName.add(temp_name);
         mapDesc.add(temp_desc);
         map2.add(temp_image2);
         map1.add(temp_image1);

            TextView txtDesc = (TextView) findViewById(R.id.tDescription);
            text = (TextView) findViewById(R.id.tTitle);
            text.setText(temp_name);

            txtDesc.setText(temp_desc);
            TextView txtName = (TextView) findViewById(R.id.tvName);
            txtName.setText(temp_bname);

            ImageView img = (ImageView)findViewById(R.id.smallImage);


            img.setImageBitmap(BitmapFactory.decodeByteArray(temp_image1, 0,temp_image1.length));
            mContext = this;
            vf = (ViewFlipper) this.findViewById(R.id.vfShow);
            vf.setOnTouchListener(new OnTouchListener() {
            @Override
                public boolean onTouch(final View view, final MotionEvent event) {
                    detector.onTouchEvent(event);
           Log.i("ew","ae");
                    return true;
                }
            });

            forNewData(temp_image2,temp_desc);

            vf.addView(addImageView(R.drawable.road_rage));

    }
}

我的日志显示为

  12-12 16:54:15.712: E/CursorWindow(744): Failed to read row 0, column 6 from a CursorWindow which has 1 rows, 6 columns.
  12-12 16:54:15.712: D/AndroidRuntime(744): Shutting down VM
  12-12 16:54:15.723: W/dalvikvm(744): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
  12-12 16:54:15.843: E/AndroidRuntime(744): FATAL EXCEPTION: main
  12-12 16:54:15.843: E/AndroidRuntime(744): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.books.bcukbook/com.books.bcukbook.DetailsActivity}: java.lang.IllegalStateException: Couldn't read row 0, col 6 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
  12-12 16:54:15.843: E/AndroidRuntime(744):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at android.os.Handler.dispatchMessage(Handler.java:99)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at android.os.Looper.loop(Looper.java:137)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at android.app.ActivityThread.main(ActivityThread.java:4424)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at java.lang.reflect.Method.invoke(Method.java:511)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at dalvik.system.NativeStart.main(Native Method)
 12-12 16:54:15.843: E/AndroidRuntime(744): 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.
 12-12 16:54:15.843: E/AndroidRuntime(744):     at android.database.CursorWindow.nativeGetString(Native Method)
 12-12 16:54:15.843: E/AndroidRuntime(744):     at android.database.CursorWindow.getString(CursorWindow.java:442)
 12-12 16:54:15.843: E/AndroidRuntime(744):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
 12-12 16:54:15.843: E/AndroidRuntime(744):     at  com.books.bcukbook.DetailsActivity.getDataAndPopulate(DetailsActivity.java:477)
 12-12 16:54:15.843: E/AndroidRuntime(744):     at com.books.bcukbook.DetailsActivity.Exists(DetailsActivity.java:443)
 12-12 16:54:15.843: E/AndroidRuntime(744):     at com.books.bcukbook.DetailsActivity.onCreate(DetailsActivity.java:292)
 12-12 16:54:15.843: E/AndroidRuntime(744):     at android.app.Activity.performCreate(Activity.java:4465)
 12-12 16:54:15.843: E/AndroidRuntime(744):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  12-12 16:54:15.843: E/AndroidRuntime(744):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
4

1 回答 1

3

创建一个新数据库而不是用新的库更新。我们如何更新现有数据库的新列

于 2012-12-12T12:13:44.207 回答