title: Android App Development - Firebase Database
body: <p>I'm building an activity in an app where users can upload a post, and other users in the app can view the post.</p>
  
  <p>I built a function called <code>loadPost()</code>
  This function will take what's there in the database and load it in my View.
  Unfortunately, I'm facing an error with the  </p>
  
  <pre><code> .addValueEventListener(ValueEventListener{
  </code></pre>
  
  <p>It's telling me that the interface needs a constructor.</p>
  
  <p>here's the function:</p>
  
  <pre><code>//*******************************************************
  //Load posts to the screen from the database
  //****************************************************
  fun loadPost(){
  
    myRef.child("posts")
      .addValueEventListener(ValueEventListener{
          override fun onDataChange(@NonNull dataSnapshot: DataSnapshot?) {
  
              try {
                  postElements.clear()
                  postElements.add(Post("0","him","url","add"))
                  postElements.add(Post("0","him","url","ads"))
  
                  //Hashmap : Key and value (represents the post and node)
                  var td= dataSnapshot!!.value as HashMap&lt;String,Any&gt;
  
                  for(key in td.keys){
                      var post= td[key] as HashMap&lt;String,Any&gt;
  
                      postElements.add(Post(key,
                              post["text"] as String,
                              post["postImage"] as String
                              ,post["userUID"] as String))
                  }
  
                  adpater!!.notifyDataSetChanged() //notify when there's an update in the adapter
              }catch (ex:Exception){}
          }
  
          override fun onCancelled(p0: DatabaseError?) {
  
          }
      })
  
  }
  </code></pre>