我创建了一个包含7列和一行的表。但是我无法使用如下代码检索存储在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)
答案 0 :(得分:3)
创建新数据库而不是使用新coulmn.how进行更新我们可以更新现有数据库的新列