The openOrCreateDatabase (String, int, null) method is undefined

I am trying to open a database as follows:

SQLiteDatabase myDatabase; myDatabase = openOrCreateDatabase("sudoku.db", Context.MODE_PRIVATE, null); 

This code works fine when I implement it in the Service class, but when I try to implement it in the onPostExecute event handler of the GeneraterThread class, implementing AsyncTask, I get the following error:

The method openOrCreateDatabase(String, int, null) is undefined for the type GeneraterThread

+6
android
source share
3 answers

It looks like you are trying to call the openOrCreateDatabase method on an instance of GeneraterThread that does not have a method (and the service class has a method). You can probably pass a reference to the Context object and call a method on it. Or use the static method SQLiteDatabase.openOrCreateDatabase ().

+5
source share

It looks like you just set the wrong arguments for the function.

The SDK has the following definitions:

 public static SQLiteDatabase openOrCreateDatabase (String path, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) public static SQLiteDatabase openOrCreateDatabase (String path, SQLiteDatabase.CursorFactory factory) public static SQLiteDatabase openOrCreateDatabase (File file, SQLiteDatabase.CursorFactory factory) 

But your call to this function is incorrect.

Perhaps you wanted to call openDatabase (String path, SQLiteDatabase.CursorFactory factory, int flags) ?

In this case, you just set the arguments in the wrong order - you do

 openOrCreateDatabase("sudoku.db", Context.MODE_PRIVATE, null); //WRONG 

instead:

 openDatabase("sudoku.db", null, Context.MODE_PRIVATE); //RIGHT 
+5
source share

Use it with a parent class

something like

 myService.this.openOrCreateDatabase 
+1
source share

All Articles