DEV Community

Papon Ahasan
Papon Ahasan

Posted on • Edited on

Error

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.socialmedia, PID: 28982
    java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionPostViewHolder{9c5e934 position=4 id=-1, oldPos=0, pLpos:0 scrap [attachedScrap] tmpDetached no parent} androidx.recyclerview.widget.RecyclerView{b6a615e VFED..... ......I. 0,0-1012,1736 #7f080194 app:id/postsRv}, adapter:com.example.socialmedia.adapter.PostAdapter@6327473, layout:androidx.recyclerview.widget.LinearLayoutManager@6e8cf30, context:com.example.socialmedia.MainActivity@8802acd
        at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:6156)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6339)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6300)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6296)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2330)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1631)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:4255)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4010)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4578)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at androidx.swiperefreshlayout.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:689)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1873)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1103)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
E/AndroidRuntime:     at com.android.internal.policy.DecorView.onLayout(DecorView.java:1331)
        at android.view.View.layout(View.java:24461)
        at android.view.ViewGroup.layout(ViewGroup.java:7412)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4614)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4036)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2924)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10513)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)
        at android.view.Choreographer.doCallbacks(Choreographer.java:866)
        at android.view.Choreographer.doFrame(Choreographer.java:797)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8751)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Enter fullscreen mode Exit fullscreen mode
    private fun getRecipientId(postId: String, callback: (recipientId: String) -> Unit){

        val postRef = FirebaseFirestore.getInstance().collection("posts").document(postId)
        postRef.get().addOnSuccessListener { documentSnapshot ->
            val post = documentSnapshot.toObject(Post::class.java)
            if (post != null) {
                val recipientId = post.createdBy.uid
                callback(recipientId)

            }
        }
    }

    getRecipientId(postId){
            recipientId = it
        }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)