Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

I'm trying to open 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 this in the onPostExecute eventhandler of the GeneraterThread class,implementing AsyncTask, I get the following error :

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

like image 933
Saurabh Verma Avatar asked Aug 15 '10 18:08

Saurabh Verma


2 Answers

It looks like your just set wrong arguments for function.

There are these definitions in SDK:

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 calling that function is wrong.

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

In this case you just set arguments in wrong order - you're doing

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

instead:

openDatabase("sudoku.db", null, Context.MODE_PRIVATE); //RIGHT
like image 104
a4vi2r Avatar answered Oct 12 '22 16:10

a4vi2r


It looks like you're trying to invoke openOrCreateDatabase method on GeneraterThread instance which doesn't have the method (and Service class has the method). You probably may pass in a reference to a Context object and invoke the method on it. Or use static method of SQLiteDatabase.openOrCreateDatabase().

like image 39
Konstantin Burov Avatar answered Oct 12 '22 16:10

Konstantin Burov