Why the database can not be known in Android SQLite?

后端 未结 2 885
攒了一身酷
攒了一身酷 2021-01-28 09:33

I\'m making an application Maps connected with SQLite which there are markers, but there is an error that the database can not be recognized, why did it happen? Can anybody help

相关标签:
2条回答
  • 2021-01-28 10:01

    Marker.db should be the name of your database and you should pass it in your constructor. The name of your table should be simply Marker:

    public class MaBase  extends SQLiteOpenHelper {
    private static final String DB_MARK  ="marker.db";
    private static final String TABLE_MARK  ="marker";
    private static final String COL_ID = "ID";
    private static final String COL_LONG = "LONGITUDE";
    private static final String COL_LAT = "LATITUDE";
    
    
    private static final String CREATE_BDD = "CREATE TABLE " + TABLE_MARK  + " ("
    + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_LONG + " TEXT NOT NULL, " +COL_LAT+" TEXT NOT NULL);";
    
    
    
    
    
    
    public MaBase (Context context, String name, CursorFactory factory, int version) {
        super(context, DB_MARK, factory, version);
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        //on créé la table à partir de la requête écrite dans la variable CREATE_BDD
        db.execSQL(CREATE_BDD);
    
    }
    

    ...

    0 讨论(0)
  • 2021-01-28 10:07

    marker.db as a table name tells to look up a table name db in database marker and you don't have the database marker attached.

    Either write the table name in double quotes like "marker.db", or better yet, rename the table to something that better resembles whatever you're putting in there, without a ..

    0 讨论(0)
提交回复
热议问题