Why this line of code gives me error?

-1

This line of code gives me error in the phrase SQLiteDatabase.CREATE_IF_NECESSARY and prevents me from doing the database. Why is this happening?

  SQLiteDatabase BaseDados=SQLiteDatabase.openOrCreateDatabase("BaseDados",SQLiteDatabase.CREATE_IF_NECESSARY,null);

The error you give is as follows:

  

Error: (16, 54) error: no suitable method found for openOrCreateDatabase (String, int,)   method SQLiteDatabase.openOrCreateDatabase (String, CursorFactory, DatabaseErrorHandler) is not applicable   (current argument int can not be converted to CursorFactory by method invocation conversion)   method SQLiteDatabase.openOrCreateDatabase (String, CursorFactory) is not applicable   (actual and formal argument lists differ in length)   method SQLiteDatabase.openOrCreateDatabase (File, CursorFactory) is not applicable   (current and formal argument lists differ in length)

The code I made is as follows:

public class GestorBaseDados {
Context contexto;
SQLiteDatabase BD;
public GestorBaseDados(Context cont) {
    contexto=cont;
    String erro=null;
    try {

  BD=SQLiteDatabase.openOrCreateDatabase("BaseDados",SQLiteDatabase.CREATE_IF_NECESSARY,null);


    }catch (Exception e)
    {
        Toast.makeText(contexto,"erro "+e.toString(),Toast.LENGTH_LONG).show();

    }



}

}

This is a class that will have all the methods to tinker with the database.

    
asked by anonymous 15.04.2016 / 20:49

1 answer

2

There is no overload for method SQLiteDatabase.openOrCreateDatabase () with this signature.

Use

SQLiteDatabase.openOrCreateDatabase("BaseDados", null);

which is the equivalent of

SQLiteDatabase.openDatabase("BaseDados", null, SQLiteDatabase.CREATE_IF_NECESSARY). 
    
15.04.2016 / 21:02