Kotlin Android Extensions giving Layout Null Pointer

To use the extensions in Fragment, you need to use with your layoutView. This should work: layoutView.gridview_all_parts.adapter = MasterListAdapter(activity, AndroidImageAssets.getAll())

You can make your layoutView global in this case.

UPDATED EXPLANATION Its something to do with view inflating. Like in butterknife, we need to bind the inflated view in case of fragment/recyclerView, similarly in case of kotlin, we need that inflate view for accessing the views in the xml.

Quoting from official documentation,

Importing synthetic properties It is convenient to import all widget properties for a specific layout in one go:

import kotlinx.android.synthetic.main.<layout>.*

Thus if the layout filename is activity_main.xml, we'd import

kotlinx.android.synthetic.main.activity_main.*.

If we want to call the synthetic properties on View, we should also import

kotlinx.android.synthetic.main.activity_main.view.*.

Once we do that, we can then invoke the corresponding extensions, which are properties named after the views in the XML file.