Skip to content

Not able to initialize object of DBHelper class which extends SqliteOpenHelper in a fragment as it takes context as arguement. #3

@shikhrsngh9044

Description

@shikhrsngh9044

Helper.kt->

class Helper(context: Context) : SQLiteOpenHelper(context, DBNAME, null, DBVERSION) {

    companion object {
        private val DBNAME = "myDb"
        private val DBVERSION = 1
    }

-->this class will take context argument but in fragment it is showing error for "context","activity","this".. i have tried all the things but not be able to resolve the error

HomeFragment.kt->

class HomeFragment : Fragment() {

    companion object {
        const val KEY = "data"
    }

    val helper = Helper(context)  //getting error-> Required:Context , Found:Context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions