Unable to get data from sqlite database

此生再无相见时 提交于 2019-12-02 08:04:10

Your param passed to SQLiteHelper is null. You can get the activity context once the fragment is attached to the activity.

Check the lifecycle of fragment https://developer.android.com/guide/components/fragments.html

Change

private val database: SQLiteHelper = SQLiteHelper(activity)

to

private var database: SQLiteHelper? = null

Overide onAttach in Fragment and initialize database

database = SQLiteHelper(activity)

https://developer.android.com/reference/android/app/Fragment.html#onAttach(android.app.Activity)

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