I am trying to retrieve a list of dates(in string format) from a PersonDOB column in database. Then I am encountering Database locked issue. I have declared open() and close() methods for the database. Even though I am getting these errors. I am unable to understand, why I am getting this error. I have read some articles like
Not only these, I have tried solutions given in other questions and articles also. But I am unable to get an appropriate solution, that suits my context. In my entire code, I am using the write operation only once. So, there is no problem of data corruption. Here is the code, where I am getting data from the database.
public String[] getDataInArray() { // get data for list and return in array form
// TODO Auto-generated method stub
SQLiteDatabase myDB;
String[] return_columns;
try {
myDB=this.openDataBase();
String DOB = "PersonDOB";
String[] columms = new String[]{ DOB };
Cursor c = myDB.query("Persons", columms, null, null, null, null, null);
int iDOB = c.getColumnIndex(DOB);
int rowcount = 0;
return_columns = new String[c.getCount()];
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{
return_columns[rowcount] = c.getString(iDOB);
rowcount = rowcount + 1;
}
if(c != null)
{
myDB.close();
c.close();
}
}catch(SQLException sqle){
throw sqle;
}
for (int i = 0;i<return_columns.length;i++)
{
Log.v("DOB", return_columns[i]); //I am not
getting this log message in the logcat.
}
return return_columns;
}
And I get the following errors in the logcat -
09-19 15:58:00.140: W/System.err(7115): java.lang.NullPointerException
09-19 15:58:00.140: W/System.err(7115): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
09-19 15:58:00.140: W/System.err(7115): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
09-19 15:58:00.200: W/System.err(7115): at com.example.fromstart.adapter.open(adapter.java:30)
09-19 15:58:00.210: W/System.err(7115): at com.example.fromstart.adapter.getDataInArray(adapter.java:222)
Thanks in advance.