In the main activity I am trying to check when the app gets open if the app database exist or not. This is because I want to get a chance to create the database and insert all the needed records on the very first run only.
But it's not working with me, it give me this error:
..Caused by: android. database. CursorindexOutOfBoundsException: Index 0 requested, with a size of 0
My first thought is that the above exception/error is not SQLiteException or I don't know exactly what I am missing.
Here is my code:
DBAdapter dbCheck = new DBAdapter(this);
boolean dbStatus;
String strData;
try {
dbCheck.open();
Cursor tblCheck = dbCheck.getThis_tblData(10); //get record no 10 - random number
strData = tblCheck.getString(5); // get the value of a field in the table
tblCheck.close();
dbCheck.close();
System.out.println("<---> Db found ");
} catch (SQLiteException e) {
//database doesn't exist yet. Create it.
System.out.println("<---> Db not found ");
Intent MakeDB = new Intent(MainActivity.this, com.kjsoft.tre.InsertData.class);
StartActivity(MakeDB);
}
Thanks everyone for your help!