【发布时间】:2010-11-03 07:13:55
【问题描述】:
我有四个选项卡,第一个选项卡在数据库中插入数据,另外两个选项卡负责使用光标显示数据。这是我的问题,但当我第一次启动应用程序时,如果我按下 2 个选项卡中的一个,数据库上没有任何内容,它会给我这个错误:
ERROR/AndroidRuntime: Caused by: android.database.sqlite.SQLiteException: no such table
我的问题是以下如何在按下 2 个选项卡之一时避免出现此错误,我只想显示一个带有空列表的空选项卡。 这是发生错误的一段代码:
void populate() {
array = new ArrayList<String>();
mydb = openOrCreateDatabase("vivo_id.db",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
Cursor c = mydb.query("VIVOID", null, null, null, null, null, null);
// start the managing cursor
startManagingCursor(c);
// move to first row
c.moveToFirst();
// continue searching until it is the last row in the column
while (c.isAfterLast() == false) {
sharable = c.getString(c.getColumnIndex("isCouponSharable"));
coupon = c.getString(c.getColumnIndex("couponImageResult"));
rawImage = c.getString(c.getColumnIndex("couponThumbnailResult"));
keyword = c.getString(c.getColumnIndex("keyword"));
histDesRes = c.getString(c.getColumnIndex("couponDescription"));
history = keyword + " \n " + histDesRes + " " + "<@>" + ""
+ rawImage+""+"<@>"+""+coupon+""+"<@>"+""+sharable;
array.add(history);
c.moveToNext();
}
strings = array.toArray(new String[array.size()]);
// close everything
c.close();
mydb.close();
}
任何帮助或指点将不胜感激,在此先感谢您。
【问题讨论】:
标签: android sqlite listview tabs