title: ViewModelProviders is not working inside my Fragment
body: <p>This is what I'm trying to do.</p>
  
  <ul>
  <li>Set an <code>ArrayList</code> of object inside a Fragment  </li>
  <li>Get that array from an    observer within the <code>FragmentActivity</code>
  container (the activity that    hosts all the fragments)</li>
  </ul>
  
  <p>So, What I have done is the following.</p>
  
  <p>First I created the <code>SharedViewModel</code> from where I will set and get the data from :</p>
  
  <h2>SharedViewModel.kt</h2>
  
  <pre><code>class SharedViewModel: ViewModel() {
  
      var personArrayObj:MutableLiveData&lt;ArrayList&lt;Person&gt;&gt; = MutableLiveData()
  
      fun setPersonArray(personArray:ArrayList&lt;Person&gt;){
          personArrayObj.value = personArray
      }
  
      val getPersonArray:LiveData&lt;ArrayList&lt;Person&gt;&gt;
      get() = personArrayObj
  
  }
  </code></pre>
  
  <p>Now , I instantiate this <code>ViewModel</code> inside the <code>MainActivity</code> that hosts all the fragments creation, so , I can get the <code>ArrayData</code> from wherever Fragment its set :</p>
  
  <h2>MainActivity.kt</h2>
  
  <pre><code>class MainActivity: FragmentActivity(){
  
  private lateinit var viewModel:SharedViewModel
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          viewModel = ViewModelProviders.of(this).get(SharedViewModel::class.java)
          viewModel.getPersonArray.observe(this, Observer { it:ArrayList&lt;Person&gt;
              Log.d("Array:",""+it)
          })
      }
  
  }
  </code></pre>
  
  <p>Then the last thing I need to do is to set the value of that Array from whatever Fragment I want, and then the host Activity will be triggered if the value has changed, so, to do this, I simple do a <code>viewModel.setValue(personArray)</code> at my desired <strong>Fragment</strong> .</p>
  
  <h2>The Problem</h2>
  
  <p>When I try to instantiate the <code>SharedViewModel</code> inside any fragment I get this problem :</p>
  
  <p><a href="https://i.stack.imgur.com/uChxn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uChxn.png" alt="enter image description here"></a></p>
  
  <p>I tried to assert !! for the null, use let too, but is not working and I wonder from where it comes that <code>FragmentActivity</code> required</p>
  
  <p>If I use <code>viewLifecycleOwner</code> instead of <code>activity</code> it says to me that it cant be called either with <strong>Fragment</strong> or <strong>FragmentActivity</strong> ?</p>
  
  <p>Any clues?</p>
  
  <p>Thanks .</p>