Android SQLite Null Pointer Exception

纵然是瞬间 提交于 2019-11-30 17:32:29

Looks like your trying to access the db when it's been closed. Perhaps placing datasource.open() at the beginning of onCreate and datasource.close() at the end of onCreate() and calling them each just once in your class would solve your problem.

If you are editing, creating and deleting items in your activity requiring multiple calls to your database, consider calling datasource.open() at the beginning of a method that accesses the database and then close() at the end of of that method.

Miloš

The best is to use the SQLiteOpenHelper class which takes care for providing instance of SQLiteDatabase, it's singleton pattern:

see Android: java.lang.IllegalStateException: database xxx.db (conn# 0) already closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!