Android SQLite Null Pointer Exception

后端 未结 2 1034
礼貌的吻别
礼貌的吻别 2021-01-04 04:14

I am getting this in LogCat:

05-20 17:16:34.721: E/AndroidRuntime(30461): FATAL EXCEPTION: main
05-20 17:16:34.721: E/AndroidRuntime(30461): java.lang.NullPo         


        
相关标签:
2条回答
  • 2021-01-04 04:42

    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

    0 讨论(0)
  • 2021-01-04 04:55

    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.

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