title: Smart cast to "GridLayoutManager" is impossible, because 'ViewManager' is a mutable property that could have changed by this time
body: <p>"Smart cast to "GridLayoutManager" is impossible, because 'ViewManager' is a mutable property that could have changed by this time"</p>
  
  <p>is the Error that AndroidStudio shows when trying to add a Divider to my RecyclerView.</p>
  
  <p><em>PixelsFragment.kt</em></p>
  
  <pre><code>class PixelsFragment : Fragment() {
  
      private lateinit var recyclerView: RecyclerView
      private lateinit var viewManager: RecyclerView.LayoutManager
      private lateinit var viewAdapter: RecyclerView.Adapter&lt;*&gt;
      private var listener: OnFragmentInteractionListener? = null
      private lateinit var pixels: List&lt;Pixel&gt;
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
  
          var numberOfColumns = 1
  
          viewManager = GridLayoutManager(this.context, numberOfColumns)
          viewAdapter = MyRecyclerViewAdapter(pixels)
  
  
          recyclerView = view!!.findViewById&lt;RecyclerView&gt;(R.id.RVJanuary).apply {
              setHasFixedSize(true)
              layoutManager = viewManager
              adapter = viewAdapter
              addItemDecoration(DividerItemDecoration(recyclerView.context, viewManager.getOrientation())) //Error on this line, underlining viewManager
          }
  
  
      }
  }
  </code></pre>
  
  <p>I found <a href="https://stackoverflow.com/a/44596284/6818446">this answer</a> which says that such a problem can be caused because the variable could happen to be <code>null</code> by the time that the line is executed, and then they provide 3 solutions. However, to my understanding, <code>viewManager</code> can by no means be <code>null</code> since I declared it as non-nullable variable. Therefore, I am looking for a different explanation and solution.</p>