java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference

tip
Do you find the tips below useful? Click on the to mark them and say thanks to Rafael Fischer Viola and rafael . Or join the community to write better ones.
  1. 0
    samebug tip
    If you're using nested fragments, you have to use childFragmentManager instead of fragmentManager.
  2. 0
    samebug tip
    When you use findViewById inside an activity it is going to look for a View inside your main_activity.xml. If it's not there, it throws this exception, try to use the right view to call findviewById.
  3. 0

    passing data from service to fragment giving null point

    Stack Overflow | 3 months ago | Neelay Srivastava
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    samebug tip
    As of SDK 23, you have to call this method with ContextCompat.getColor(context, R.color.my_color) so it works with previous API as well. Also, you have to add the support V4 library to your dependencies: "compile 'com.android.support:support-v4:23.0.1'"

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference

      at beatbox.neelay.anotherbeat.Fragment.Songs.onCreateView()
    2. beatbox.neelay.anotherbeat
      Songs.onCreateView
      1. beatbox.neelay.anotherbeat.Fragment.Songs.onCreateView(Songs.java:55)
      1 frame
    3. Android Support v4
      FragmentPagerAdapter.finishUpdate
      1. android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
      2. android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298)
      3. android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
      4. android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
      5. android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
      6. android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1969)
      7. android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:620)
      8. android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
      8 frames
    4. com.antonyt.infiniteviewpager
      InfinitePagerAdapter.finishUpdate
      1. com.antonyt.infiniteviewpager.InfinitePagerAdapter.finishUpdate(InfinitePagerAdapter.java:67)
      1 frame
    5. Android Support v4
      ViewPager.onMeasure
      1. android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
      2. android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
      3. android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642)
      3 frames
    6. Android Platform
      ViewGroup.measureChildWithMargins
      1. android.view.View.measure(View.java:18811)
      2. android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
      3. android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
      4. android.view.View.measure(View.java:18811)
      5. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
      5 frames
    7. android.support.design
      CoordinatorLayout.onMeasure
      1. android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
      2. android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:786)
      2 frames
    8. Android Platform
      FrameLayout.onMeasure
      1. android.view.View.measure(View.java:18811)
      2. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
      3. android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
      3 frames
    9. Android v7
      ContentFrameLayout.onMeasure
      1. android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
      1 frame
    10. Android Platform
      FrameLayout.onMeasure
      1. android.view.View.measure(View.java:18811)
      2. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
      3. android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
      4. android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
      5. android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
      6. android.view.View.measure(View.java:18811)
      7. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
      8. android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
      9. android.view.View.measure(View.java:18811)
      10. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
      11. android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
      12. android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
      13. android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
      14. android.view.View.measure(View.java:18811)
      15. android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
      16. android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
      16 frames
    11. Android
      PhoneWindow$DecorView.onMeasure
      1. com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2645)
      1 frame
    12. Android Platform
      Handler.dispatchMessage
      1. android.view.View.measure(View.java:18811)
      2. android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2127)
      3. android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1243)
      4. android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1479)
      5. android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1134)
      6. android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6045)
      7. android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
      8. android.view.Choreographer.doCallbacks(Choreographer.java:672)
      9. android.view.Choreographer.doFrame(Choreographer.java:608)
      10. android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
      11. android.os.Handler.handleCallback(Handler.java:739)
      12. android.os.Handler.dispatchMessage(Handler.java:95)
      12 frames