title: Kotlin / Firebase / Android Studio- java.util.NoSuchElementException: List is empty
body: <p>I made an application like Instagram and everything works fine, except when new user create a profile, the application stops/crash because it doesn't have anything to show on the home page and it drops `java.util.NoSuchElementException: List is empty.</p>
  
  <p>here is the full error </p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.homeactivity, PID: 14508
  java.util.NoSuchElementException: List is empty.
      at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:196)
      at com.example.homeactivity.activities.MainActivity$onStart$1.invoke(MainActivity.kt:61)
      at com.example.homeactivity.activities.MainActivity$onStart$1.invoke(MainActivity.kt:30)
      at com.example.homeactivity.utils.ValueEventListenerAdapter.onDataChange(ValueEventListenerAdapter.kt:13)
      at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.0:75)
      at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.0:63)
      at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.0:55)
      at android.os.Handler.handleCallback(Handler.java:751)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6119)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  </code></pre>
  
  <p>here is MainActivity.kt line 51-66</p>
  
  <pre><code>override fun onStart() {
      super.onStart()
      val currentUser = mFirebase.auth.currentUser
      if(currentUser == null){
          startActivity(Intent(this, LoginActivity::class.java))
          finish()
      } else {
          mFirebase.database.child("feed-posts").child(currentUser.uid)
              .addValueEventListener(ValueEventListenerAdapter { it -&gt;
                  val posts = it.children.map { it.getValue(FeedPost::class.java)!! }
                  Log.d(TAG, "feedPosts: ${posts.first().timestampDate()}")
                  feed_recycler.adapter = FeedAdapter(posts)
                  feed_recycler.layoutManager = LinearLayoutManager(this)
              })
      }
  }
  </code></pre>
  
  <p>MainActivity.kt line 30-32</p>
  
  <pre><code>class MainActivity : BaseActivity(0) {
  private val TAG = "MainActivity"
  private lateinit var mFirebase: FirebaseHelper
  </code></pre>
  
  <p>ValueEventListenerAdapter.kt line 8-19</p>
  
  <pre><code>    class ValueEventListenerAdapter(val handler: (DataSnapshot) -&gt; Unit): ValueEventListener {
          private val TAG = "ValueEventListenerAdapt"
  
          override fun onDataChange(data: DataSnapshot) {
             handler(data)
          }
  
          override fun onCancelled(error: DatabaseError) {
             Log.e(TAG, "onCancelled: ", error.toException())
          }
      }
  </code></pre>