I have four tabs which the first one inserts data on the database, the other 2 tabs take care of displaying the data using a cursor. here is my problem though when I first start the app and there is nothing on the database if I press one of the 2 tabs it gives me this error:
ERROR/AndroidRuntime: Caused by: android.database.sqlite.SQLiteException: no such table
my question is the following how can I avoid getting this error when pressing one of 2 tabs, I would like just to display an empty tab with an empty list.
Here is a piece of code where the error happens:
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();
}
Any help or pointers would be greatly appreciated, Thank you so much in advance.
I was missing the most imprtant element which the following, I learned from it hopefully other people will as well.
myDbHelper.getReadableDatabase();
@ the beginning of the function.