Unable to get data from sqlite database

后端 未结 1 1404
终归单人心
终归单人心 2020-12-12 06:28

The problem is that when I run my code the app is stopping with an error (java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twixt.pranav.pos/com.twixt.p

相关标签:
1条回答
  • 2020-12-12 06:52

    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)

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