Kotline : Recyclerview and Fragment Error E/RecyclerView: No adapter attached; skipping layout : <p>I create a recyclerview in activity and when I'm trying to incorporate Fragment it giving me <strong>"Error E/RecyclerView: No adapter attached; skipping layout"</strong></p>

<p>My old sample Output
<a href="https://i.stack.imgur.com/NCmTI.png" rel="nofollow noreferrer">My old sample Output</a></p>

<p>Now I wanted to place bottom navigation and Fragment. Below is my code</p>

<p>my Activity file : <strong>activity_main.xml</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingView"
    android:background="@color/colorAccent"
    tools:context=".MainActivity"&gt;

    &lt;!-- &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" /&gt;
--&gt;

    &lt;TextView
        android:id="@+id/Voc"
        android:layout_height="wrap_content"
        android:text="Section 1"
        android:layout_width="wrap_content"
        android:paddingTop="3dp"
        android:paddingBottom="3dp"
        android:paddingLeft="10dp"
        android:textSize="25sp"
        app:layout_constraintTop_toTopOf="parent"/&gt;

    &lt;android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
       android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"

        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toBottomOf="@id/Voc"
       /&gt;

    &lt;TextView
        android:id="@+id/sep_id"
        android:layout_height="wrap_content"
        android:text="Section 2"
        android:layout_width="wrap_content"
        android:paddingTop="6dp"
        android:paddingBottom="3dp"
        android:textSize="25sp"
        android:paddingLeft="10dp"
        app:layout_constraintTop_toBottomOf="@id/my_recycler_view"/&gt;

     &lt;android.support.v7.widget.RecyclerView
        android:id="@+id/speaking"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/sep_id"
         android:paddingLeft="10dp"/&gt;



&lt;/android.support.constraint.ConstraintLayout&gt;</code></pre>
</div>
</div>
</p>

<p>Recycler layout : <strong>row_post.xml</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="120dp"
    android:layout_height="120dp"

   &gt;
  &lt;!--  &lt;LinearLayout
        android:id="@+id/view_main_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"&gt; --&gt;


            &lt;ImageView
                android:id="@+id/image_view_id_row"
                android:layout_width="match_parent"
                android:layout_marginRight="10dp"
                android:src="@drawable/sp2"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                android:layout_height="90dp"
                android:background="@color/colorPrimary"
                android:scaleType="fitXY"
                 /&gt;

            &lt;TextView
                android:id="@+id/username"
                android:text="Loading Username.."
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                app:layout_constraintTop_toBottomOf="@id/image_view_id_row"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                android:textAlignment="center"
                android:layout_marginRight="10dp"

                /&gt;
        &lt;!--   "
          android:src="@drawable/sp1"--&gt;

&lt;/android.support.constraint.ConstraintLayout&gt;</code></pre>
</div>
</div>
</p>

<p>Main Layout or landing page with Frame : activity_main2.xml</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/containerm"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"&gt;


    &lt;FrameLayout
        android:id="@+id/frame_layout_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
       /&gt;


    &lt;android.support.design.widget.BottomNavigationView
        android:id="@+id/navigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:layout_gravity="bottom"
        android:layout_weight="0"
        android:background="?android:attr/windowBackground"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:menu="@menu/navigation"/&gt;


&lt;/LinearLayout&gt;</code></pre>
</div>
</div>
</p>

<p>kotlin class : FragmentCall(link to activity_main.xml)</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>package com.ammara.ammara.TEST

import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.net.Uri
import android.support.v7.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import com.ammara.ammara.ielts.model.Samples

class FragmentCall:Fragment() {

    val TAG="Call Fragment"
    override fun onAttach(context: Context?) {
        super.onAttach(context)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {



        return inflater!!.inflate(R.layout.activity_main,container,false)
         }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
    }

    override fun onStart() {
        super.onStart()
    }

    override fun onResume() {
        super.onResume()
    }

    override fun onPause() {
        super.onPause()
    }

    override fun onStop() {
        super.onStop()
    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun onDetach() {
        super.onDetach()
    }
}</code></pre>
</div>
</div>
</p>

<p>kotlin class Main2Activity (link to activity_main2.xml)</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>package com.ammara.ammara.TEST

import android.app.AlertDialog
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import com.ammara.ammara.ielts.R.menu.navigation
import com.ammara.ammara.ielts.model.Samples
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main2.*

class Main2Activity : AppCompatActivity() {


    var isFragmentOneLoaded=true
    val manager=supportFragmentManager

    private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -&gt;
        when (item.itemId) {
            R.id.navigation_home -&gt; {

                ShowFragmentOne()
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_dashboard -&gt; {
                ShowFragmentOne()
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_notifications -&gt; {
                ShowFragmentOne()
                return@OnNavigationItemSelectedListener true
            }
        }
        false
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)



        ShowFragmentOne()

        navigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

            }

    fun ShowFragmentOne(){


        val transaction=manager.beginTransaction()
        val fragment=FragmentCall()
        transaction.replace(R.id.frame_layout_id,fragment)
        transaction.addToBackStack(null)
        transaction.commit()
        AlertDialog.Builder( this)

                .setMessage(this.packageName)
                .setPositiveButton("ok") { p0, p1 -&gt;

                }
                .create()
                .show()
    }
}</code></pre>
</div>
</div>
</p>

<p>Adaptor class link to row_post</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>package com.ammara.ammara.TEST
import android.content.Intent
import android.os.Parcel
import android.os.Parcelable
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.ammara.ammara.TEST.model.Samples
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.row_post.view.*
import android.os.Bundle
import android.support.v4.content.ContextCompat.startActivity


class PostsAdapter (val posts: ArrayList&lt;Samples&gt;) : RecyclerView.Adapter&lt;PostsAdapter.PostsViewHolder&gt; (){



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PostsAdapter.PostsViewHolder {
        val view: View = LayoutInflater.from(parent.context).inflate(R.layout.row_post,parent,false)
        val holder= PostsViewHolder(view)
        view.setOnClickListener{
            val intent= Intent(parent.context, SampleTest::class.java)
            val extras = Bundle()
            extras.putString("title",posts[holder.adapterPosition].title)
            extras.putString("photoUrl",posts[holder.adapterPosition].photoUrl.toString())
            intent.putExtras(extras)
            parent.context.startActivity(intent)
        }
        return holder
    }

    override fun getItemCount() = posts.size

    override fun onBindViewHolder(holder: PostsViewHolder, position: Int) {
        holder.title.text=posts[position].title
        holder.image.setImageURI(posts[position].photoUrl)
      //  Picasso.get().load(posts[position].photoUrl).into(holder.image)


    }

    class PostsViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
        val image: ImageView=itemView.findViewById(R.id.image_view_id_row)
        val title: TextView=itemView.findViewById(R.id.username)
    }


}</code></pre>
</div>
</div>
</p>

<p>Now the problem is that....earlier I was having below lines of code in my activity, now activity is not getting call due to fragment. where do i put below line of code</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code> val myImageList = intArrayOf(R.drawable.sp1, R.drawable.sp2, R.drawable.sp3, R.drawable.sp4, R.drawable.sp5, R.drawable.sp6, R.drawable.sp7, R.drawable.sp8, R.drawable.sp9, R.drawable.sp10)
        val myImageList1 = arrayListOf("@drawable/sp1", "@drawable/sp2", "@drawable/sp3", "@drawable/sp4", "@drawable/sp5", "@drawable/sp6", "@drawable/sp7", "@drawable/sp8", "@drawable/sp9", "@drawable/sp10")
        val myImageList2 = arrayListOf("sp1", "sp2", "sp3", "sp4", "sp5", "sp6", "sp7", "sp8", "sp9", "sp10")

        val samples= arrayListOf&lt;Samples&gt;()
        for (i in 0..9){
            val imgUri = Uri.parse("android.resource://com.ammara.ammara.ielts/"+myImageList[i])
            samples.add(Samples("Sample# $i", photoUrl=imgUri,price=1.99))
        }

        val vSpeaking= arrayListOf&lt;Samples&gt;()
        for (i in 0..9){
            val imgUri = Uri.parse("android.resource://com.ammara.ammara.ielts/"+myImageList[i])
            vSpeaking.add(Samples("Sample# $i",photoUrl=imgUri,price=1.99))
        }
        my_recycler_view.layoutManager =LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false)
        my_recycler_view.adapter = PostsAdapter(samples)

        speaking.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false)
        speaking.adapter = PostsAdapter(vSpeaking)</code></pre>
</div>
</div>
</p>
