java.lang.NullPointerException: Attempt to invoke virtual method 'int android.text.Layout.getLineForOffset(int)' on a null object reference

Stack Overflow | Bhushan Babar | 4 months ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    return layout.getLineForOffset(selectionStart); crashing my app

    Stack Overflow | 4 months ago | Bhushan Babar
    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.text.Layout.getLineForOffset(int)' on a null object reference

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke virtual method 'int android.text.Layout.getLineForOffset(int)' on a null object reference

      at com.example.tabstrial2.TabFragment1.getCurrentCursorLine()
    2. com.example.tabstrial2
      TabFragment1$2.onTextChanged
      1. com.example.tabstrial2.TabFragment1.getCurrentCursorLine(TabFragment1.java:451)
      2. com.example.tabstrial2.TabFragment1$2.onTextChanged(TabFragment1.java:169)
      2 frames
    3. Android Platform
      View.restoreHierarchyState
      1. android.widget.TextView.sendOnTextChanged(TextView.java:7689)
      2. android.widget.TextView.setText(TextView.java:4070)
      3. android.widget.TextView.setText(TextView.java:3925)
      4. android.widget.EditText.setText(EditText.java:85)
      5. android.widget.TextView.setText(TextView.java:3900)
      6. android.widget.TextView.onRestoreInstanceState(TextView.java:3800)
      7. android.view.View.dispatchRestoreInstanceState(View.java:13754)
      8. android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2894)
      9. android.view.View.restoreHierarchyState(View.java:13732)
      9 frames
    4. Android Support v4
      ViewPager.setCurrentItem
      1. android.support.v4.app.Fragment.restoreViewState(Fragment.java:477)
      2. android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1135)
      3. android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
      4. android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
      5. android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1638)
      6. android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
      7. android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
      8. android.support.v4.view.ViewPager.populate(ViewPager.java:1240)
      9. android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:670)
      10. android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:632)
      11. android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:613)
      11 frames
    5. com.example.tabstrial2
      MainActivity.onNavigationItemSelected
      1. com.example.tabstrial2.MainActivity.onNavigationItemSelected(MainActivity.java:569)
      1 frame
    6. android.support.design
      NavigationView$1.onMenuItemSelected
      1. android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:153)
      1 frame
    7. android.support.v7
      MenuBuilder.performItemAction
      1. android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:810)
      2. android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
      3. android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:957)
      3 frames
    8. android.support.design
      NavigationMenuPresenter$1.onClick
      1. android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:328)
      1 frame
    9. Android Platform
      ActivityThread.main
      1. android.view.View.performClick(View.java:4783)
      2. android.view.View$PerformClick.run(View.java:19887)
      3. android.os.Handler.handleCallback(Handler.java:739)
      4. android.os.Handler.dispatchMessage(Handler.java:95)
      5. android.os.Looper.loop(Looper.java:135)
      6. android.app.ActivityThread.main(ActivityThread.java:5290)
      6 frames
    10. Java RT
      Method.invoke
      1. java.lang.reflect.Method.invoke(Native Method)
      2. java.lang.reflect.Method.invoke(Method.java:372)
      2 frames
    11. Android
      ZygoteInit.main
      1. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911)
      2. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
      2 frames