title: Getting kotlin.TypeCastException when trying to use parcelable on an ArrayList variable which contains null fields
body: <p>I literally started yesterday with using Kotlin, so I am still having a hard time understanding the underlying principles. I want to send an object via intent to another activity and implemented parcelable on the object. The object contains some MutableLists in the form of:</p>
  
  <pre><code>var favoritePlaces: MutableList&lt;String?&gt;? = null
  </code></pre>
  
  <p>I used this method constructor to parcelize it:</p>
  
  <pre><code>constructor(`in`: Parcel) {
    `in`.readList(favoritePlaces, String::class.java.classLoader)
  }
  </code></pre>
  
  <p>This is the error I get  in Android Studio since a type mismatch exists:</p>
  
  <p><a href="https://i.stack.imgur.com/JDL3b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JDL3b.png" alt="Android Studio error"></a></p>
  
  <p>I tried to go with the suggestion of Android Studio leaving me with this here in the constructor:</p>
  
  <pre><code>constructor(`in`: Parcel) {
     `in`.readList(favoritePlaces as List&lt;*&gt;, String::class.java.classLoader)
   }
  </code></pre>
  
  <p>And in the writeToParcel method:</p>
  
  <pre><code>override fun writeToParcel(dest: Parcel, flags: Int) {
      dest.writeList(favoritePlaces as List&lt;*&gt;?)
  }
  </code></pre>
  
  <p>But when I try to use this, then I get the following error message when starting the Activity:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.test.app.Activity}:
    kotlin.TypeCastException: null cannot be cast to non-null type
    kotlin.collections.List&lt;*></p>
  </blockquote>
  
  <p>I do understand that the type kotlin.collections.List&lt;*> is a non-null type and since I have some null fields in my arrays, it makes sense that this error occurs. My question is now, how can I parcelize String Arrays in Kotlin with non-empty as well as empty fields???</p>