java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

Stack Overflow | shady | 6 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    NullPointerException when adding header to heterogeneous RecyclerView

    Stack Overflow | 6 months ago | shady
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

      at com.example.shashankdc.learn.Medals.Medals_Adapter.onBindViewHolder()
    2. com.example.shashankdc
      Medals_Adapter.onBindViewHolder
      1. com.example.shashankdc.learn.Medals.Medals_Adapter.onBindViewHolder(Medals_Adapter.java:62)
      2. com.example.shashankdc.learn.Medals.Medals_Adapter.onBindViewHolder(Medals_Adapter.java:17)
      2 frames
    3. Android v7
      RecyclerView.onLayout
      1. android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5138)
      2. android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4433)
      3. android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4326)
      4. android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1955)
      5. android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1364)
      6. android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1327)
      7. android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
      8. android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2713)
      9. android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3011)
      9 frames
    4. Android Platform
      ViewGroup.layout
      1. android.view.View.layout(View.java:15695)
      2. android.view.ViewGroup.layout(ViewGroup.java:4981)
      3. android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
      4. android.view.View.layout(View.java:15695)
      5. android.view.ViewGroup.layout(ViewGroup.java:4981)
      5 frames
    5. android.support.design
      CoordinatorLayout.onLayout
      1. android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1009)
      2. android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:719)
      3. android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
      4. android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:984)
      5. android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:732)
      5 frames
    6. Android Platform
      Handler.handleCallback
      1. android.view.View.layout(View.java:15695)
      2. android.view.ViewGroup.layout(ViewGroup.java:4981)
      3. android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
      4. android.widget.FrameLayout.onLayout(FrameLayout.java:508)
      5. android.view.View.layout(View.java:15695)
      6. android.view.ViewGroup.layout(ViewGroup.java:4981)
      7. android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
      8. android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
      9. android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
      10. android.view.View.layout(View.java:15695)
      11. android.view.ViewGroup.layout(ViewGroup.java:4981)
      12. android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
      13. android.widget.FrameLayout.onLayout(FrameLayout.java:508)
      14. android.view.View.layout(View.java:15695)
      15. android.view.ViewGroup.layout(ViewGroup.java:4981)
      16. android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
      17. android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
      18. android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
      19. android.view.View.layout(View.java:15695)
      20. android.view.ViewGroup.layout(ViewGroup.java:4981)
      21. android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
      22. android.widget.FrameLayout.onLayout(FrameLayout.java:508)
      23. android.view.View.layout(View.java:15695)
      24. android.view.ViewGroup.layout(ViewGroup.java:4981)
      25. android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2186)
      26. android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1920)
      27. android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1106)
      28. android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6018)
      29. android.view.Choreographer$CallbackRecord.run(Choreographer.java:792)
      30. android.view.Choreographer.doCallbacks(Choreographer.java:596)
      31. android.view.Choreographer.doFrame(Choreographer.java:557)
      32. android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:778)
      33. android.os.Handler.handleCallback(Handler.java:739)
      33 frames