question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addSlide IndexOutOfBoundsException on Android 7

See original GitHub issue

AppIntro Version: 5.1.0

Device/Android Version: Huawei P9 Plus / Android 7.0

Issue details / Repro steps / Use case background: The tutorial slides load sucessfully and the first video is played but when I want to go to the next video it crashes with the exception shown below. This only happens on Android 7. On a Samsung S10 with Android 10 it works fine.

Your Code:

public class TutorialActivity extends AppIntro {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Note here that we DO NOT use setContentView();

        boolean full = getIntent().getBooleanExtra("full", true);

        // Add your slide fragments here.
        // AppIntro will automatically generate the dots indicator and buttons.
        if (full) {
            addSlide(TutorialFragment.newInstance("1. Keyboard", R.raw.keyboard));
            addSlide(TutorialFragment.newInstance("2. Self-Reports", R.raw.self_report));
            addSlide(TutorialFragment.newInstance("2.1. Example 1", R.raw.example1));
            addSlide(TutorialFragment.newInstance("2.2. Example 2", R.raw.example2));
            addSlide(TutorialFragment.newInstance("2.3. Example 3", R.raw.example3));
            addSlide(TutorialFragment.newInstance("2.4. Example 4", R.raw.example4));
            addSlide(TutorialFragment.newInstance("3. App", R.raw.app));
        } else {
            addSlide(TutorialFragment.newInstance("Definition", R.raw.self_report));
            addSlide(TutorialFragment.newInstance("Example 1", R.raw.example1));
            addSlide(TutorialFragment.newInstance("Example 2", R.raw.example2));
            addSlide(TutorialFragment.newInstance("Example 3", R.raw.example3));
            addSlide(TutorialFragment.newInstance("Example 4", R.raw.example4));
        }

        // Set Background color
        setBarColor(Color.parseColor("#0069B4"));
        setSeparatorColor(Color.parseColor("#0069B4"));

        // Show Skip button
        showSkipButton(true);

        // Show how far progress is
        setProgressButtonEnabled(true);

        // Don't Turn vibration on
        setVibrate(false);

        // Set animation for changing fragment
        setZoomAnimation();
    }

    @Override
    public void onSkipPressed(Fragment currentFragment) {
        super.onSkipPressed(currentFragment);

        finishTutorial();
    }

    @Override
    public void onDonePressed(Fragment currentFragment) {
        super.onDonePressed(currentFragment);

        finishTutorial();
    }

    @Override
    public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) {
        super.onSlideChanged(oldFragment, newFragment);

        if(newFragment instanceof TutorialFragment) {
            ((TutorialFragment) newFragment).startVideo();
        }
        if(oldFragment instanceof TutorialFragment) {
            ((TutorialFragment) oldFragment).stopVideo();
        }
    }

    /**
     * Closes the Tutorial activity
     *
     */
    private void finishTutorial() {
        finish();
    }
}

public class TutorialFragment extends Fragment {

    private static final String EXTRA_TITLE = "extra_title";
    public static final String EXTRA_VIDEO = "extra_video";

    private VideoView mVideoView;

    public static final TutorialFragment newInstance(String title, int videoId) {
        // Load tutorial data
        TutorialFragment f = new TutorialFragment();
        Bundle bd = new Bundle(2);
        bd.putString(EXTRA_TITLE, title);
        bd.putInt(EXTRA_VIDEO, videoId);
        f.setArguments(bd);
        return f;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_tutorial, container, false);

        // Set tutorial title
        TextView title = rootView.findViewById(R.id.tutorial_title);
        title.setText(getArguments().getString(EXTRA_TITLE));

        // Set tutorial video
        mVideoView = rootView.findViewById(R.id.tutorial_video);

        // Load video file
        String path = "android.resource://" + getContext().getPackageName() + "/" + getArguments().getInt(EXTRA_VIDEO);
        Uri uri= Uri.parse(path);

        // Set video parameters
        mVideoView.setMediaController(null);
        mVideoView.setVideoURI(uri);
        mVideoView.requestFocus();

        return rootView;
    }

    /**
     * Start running the video
     *
     */
    public void startVideo() {
        mVideoView.start();
        mVideoView.seekTo(0);
    }

    /**
     * Stops running the video
     *
     */
    public void stopVideo() {
        mVideoView.stopPlayback();
    }
}

Stack trace / LogCat:

java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

--------- Stack trace ---------

    java.util.ArrayList.get(ArrayList.java:411)
    androidx.viewpager.widget.ViewPager.getChildDrawingOrder(ViewPager.java:804)
    android.view.View.populateAccessibilityNodeInfoDrawingOrderInParent(View.java:7010)
    android.view.View.onInitializeAccessibilityNodeInfoInternal(View.java:6969)
    android.view.View.onInitializeAccessibilityNodeInfo(View.java:6584)
    android.view.View.createAccessibilityNodeInfoInternal(View.java:6543)
    android.view.View.createAccessibilityNodeInfo(View.java:6528)
    android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:145)
    android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:119)
    android.view.View.onInitializeAccessibilityEventInternal(View.java:6480)
    android.view.View.onInitializeAccessibilityEvent(View.java:6468)
    android.view.View.sendAccessibilityEventUncheckedInternal(View.java:6329)
    android.view.View.sendAccessibilityEventUnchecked(View.java:6314)
    android.view.View$SendViewStateChangedAccessibilityEvent.run(View.java:23705)
    android.view.View$SendViewStateChangedAccessibilityEvent.runOrPost(View.java:23738)
    android.view.View.notifyViewAccessibilityStateChangedIfNeeded(View.java:9476)
    android.view.View.onFocusChanged(View.java:6197)
    android.view.View.clearFocusInternal(View.java:6101)
    android.view.View.unFocus(View.java:6134)
    android.view.ViewGroup.unFocus(ViewGroup.java:997)
    android.view.ViewGroup.unFocus(ViewGroup.java:997)
    android.view.ViewGroup.unFocus(ViewGroup.java:997)
    android.view.ViewGroup.requestChildFocus(ViewGroup.java:734)
    android.view.ViewGroup.addViewInner(ViewGroup.java:4503)
    android.view.ViewGroup.addView(ViewGroup.java:4312)
    androidx.viewpager.widget.ViewPager.addView(ViewPager.java:1485)
    android.view.ViewGroup.addView(ViewGroup.java:4252)
    android.view.ViewGroup.addView(ViewGroup.java:4225)
    androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:326)
    androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
    androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
    androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
    androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
    androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
    androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
    androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
    androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
    androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1818)
    androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
    androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:246)
    androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
    androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:669)
    androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:631)
    androidx.viewpager.widget.ViewPager.setCurrentItem(ViewPager.java:612)
    com.github.paolorotolo.appintro.AppIntroViewPager.setCurrentItem(AppIntroViewPager.java:84)
    com.github.paolorotolo.appintro.AppIntroViewPager.goToNextSlide(AppIntroViewPager.java:47)
    com.github.paolorotolo.appintro.AppIntroBase.changeSlide(AppIntroBase.java:965)
    com.github.paolorotolo.appintro.AppIntroBase.access$300(AppIntroBase.java:41)
    com.github.paolorotolo.appintro.AppIntroBase$NextButtonOnClickListener.onClick(AppIntroBase.java:1059)
    android.view.View.performClick(View.java:5646)
    android.view.View$PerformClick.run(View.java:22459)
    android.os.Handler.handleCallback(Handler.java:761)
    android.os.Handler.dispatchMessage(Handler.java:98)
    android.os.Looper.loop(Looper.java:156)
    android.app.ActivityThread.main(ActivityThread.java:6523)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
kebirocommented, May 12, 2021

Hey,

we’ve also had this issue.

E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.get(ArrayList.java:437)
        at com.github.appintro.internal.viewpager.PagerAdapter.getItem(PagerAdapter.kt:13)
        at com.github.appintro.AppIntroBase$onPostCreate$1.run(AppIntroBase.kt:458)
        at android.os.Handler.handleCallback(Handler.java:869)
        at android.os.Handler.dispatchMessage(Handler.java:101)
        at android.os.Looper.loop(Looper.java:206)
        at android.app.ActivityThread.main(ActivityThread.java:6749)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)

I can reproduce this by not adding any slides in onCreate.

It’s version 6.0.0.

0reactions
cortinicocommented, Feb 3, 2022

Should someone have a similar problem, please open a new issue and we’ll try to fix it 👍

Please open a separate issue and provide a reproducer 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7
USER_IMG.length(); returns the length of the String (the number of chars of "product_images"). You should return the size of the data set ...
Read more >
IndexOutOfBoundsException - Android Developers
IndexOutOfBoundsException ; IndexOutOfBoundsException; IndexOutOfBoundsException ... Constructs an IndexOutOfBoundsException with no detail message.
Read more >
IndexOutOfBoundsException (Java Platform SE 8 )
Thrown to indicate that an index of some sort (such as to an array, to a string, or to a vector) is out...
Read more >
IndexOutOfBoundsException in RecyclerView ... - Issue Tracker
IndexOutOfBoundsException : Inconsistency detected. ... google.com> #90 Dec 7, 2015 02:50PM ... 7 at android.support.v7.widget.
Read more >
fix: Property dependencies and dev_dependencies are not ...
addSlide IndexOutOfBoundsException on Android 7, 19, 2020-07-07, 2022-11-13. [BUG] TFT 43 Screen goes white after 2-4 hours printing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found