Q: Integer cannot be cast to android.support.design.widget.FloatingActionButton I am trying to access a Floating Action Button inside a fragment but for some reason, I cannot.  I keep getting errors.  I have tried everything and nothing seems to work.  Here is the code inside my fragment:
import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.ntx_deisgns.cyberchatter.cyberchatter.Message
import com.ntx_deisgns.cyberchatter.cyberchatter.R
import kotlinx.android.synthetic.main.groups.*
import kotlinx.android.synthetic.main.groups2.*

class groups2 : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
//        inflater.inflate(R.layout.groups2, container, false)
        val fab = R.id.fab as FloatingActionButton

        fab.setOnClickListener {

            if (!mainActivityEditText.text.toString().isEmpty()){
                sendData()
            }else{
//                Toast.makeText(this, "Please enter a message", Toast.LENGTH_SHORT).show()
            }
        }
        return inflater.inflate(R.layout.groups2, container, false)
    }

    private fun sendData(){

        val editText = groupInput
        val database = FirebaseDatabase.getInstance()
        val myRef = database.getReference("message")

        myRef.setValue(Message(editText.text.toString()))
        val mDatabase: DatabaseReference? = null
        mDatabase?.
                child("messages")?.
                child(java.lang.String.valueOf(System.currentTimeMillis()))?.
                setValue(Message(editText.text.toString()))

        //clear the text
        editText.setText("")
    }

    companion object {
        fun newInstance(): groups2 = groups2()
    }
}

What am I doing wrong?  Why is it so hard to access a setOnClickListener within a fragment?
UPDATE:
Here's my groups2.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/groups2_relative"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="60dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="55dp"
    tools:context="com.ntx_deisgns.cyberchatter.cyberchatter.MainActivity">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/myFab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:clickable="true"
        android:focusable="true"
        android:src="@drawable/ic_send_black_24dp"
        android:tint="@android:color/white"
        app:fabSize="mini"  />

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_toStartOf="@id/myFab">

        <EditText
            android:id="@+id/groupInput"
            android:layout_width="match_parent"
            android:layout_height="57dp"
            android:hint="Please enter your text here" />

    </android.support.design.widget.TextInputLayout>

    <ListView
        android:id="@+id/list_of_messages"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/myFab"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="16dp"
        android:divider="@android:color/transparent"
        android:dividerHeight="16dp" />
</RelativeLayout>


A: You need to inflate the view before calling findViewById on it. Accessing the floating action button before inflation is causing the null pointer exception.
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        //inflate and store view
        val view =  inflater.inflate(R.layout.groups2, container, false)
        val fab = view.findViewById(R.id.fab) as FloatingActionButton
        //If using kotlinx then above line is not needed

        fab.setOnClickListener {
                   //do your thing...
           }
        return view
    }

