Android:getWritableDatabase/getReadableDatabase无法调用onCreate

来源:互联网 发布:电脑大型网络3d游戏 编辑:程序博客网 时间:2024/05/16 06:38

主要原因是:

当调用getWritableDatabase/getReadableDatabase时,onCreate只有在数据库第一次创建时调用,如果数据库存在,则直接返回相应的引用。

参考官方说明:

http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onCreate(android.database.sqlite.SQLiteDatabase)

public abstract void onCreate (SQLiteDatabase db)

Since: API Level 1

Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.

Parameters
dbThe database.

在模拟器中调试时,通过DDMS的File Explorer功能找到相应的/data/data/your_pakcage下的databases目录,删除掉数据库文件即可。


原创粉丝点击