Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting exception IndexOutOfBoundsException FragmentManagerImpl after sharing something to the apps

I get this exception just after sharing content to my app and just in the case when the app is already started. If I start the app directly all the things work good. If I share something to my app and the app is not already running all the things work good. They don't work just in the first case.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_real_debrid);

    LoginStore.init(getApplicationContext());
    AnalyticsManager.init(getApplicationContext());
    RDDownloadManager.init(this);
    ResponseHandlerManager.init(this);
    AppRater.app_launched(this, getString(R.string.app_name));
    layout = findViewById(R.id.drawer_layout);
    supportActionBar = getSupportActionBar();
    mTitle = mDrawerTitle = getTitle();
    setFragment(FragmentList.findFragmentById(0).getFragment(), false);
    if (layout instanceof DrawerLayout) {
        mDrawerLayout = (DrawerLayout) layout;
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        supportActionBar.setHomeButtonEnabled(true);
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                if (supportActionBar.getTitle().equals(mDrawerTitle))
                    supportActionBar.setTitle(mTitle);
                supportInvalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                mTitle = supportActionBar.getTitle();
                supportActionBar.setTitle(mDrawerTitle);
                supportInvalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

    } else {
        getSupportActionBar().setHomeButtonEnabled(false);
    }
    Credentials c = LoginStore.getCredential();
    if (c.getLogin() == null || c.getPasswd() == null)
    {
        Intent loginIntent;         
        loginIntent = new Intent(this, Login.class);
        startActivityForResult(loginIntent, 0);
    }

}

public void setFragment(IFragment mFragment, boolean mAnimate) {
    final FragmentTransaction mFragmentTransaction = getSupportFragmentManager().beginTransaction();
    mContent = mFragment;
    if (mAnimate)
        mFragmentTransaction.setCustomAnimations(R.anim.fragment_in, R.anim.fragment_out);
    mFragmentTransaction.replace(R.id.content_frame, (Fragment) mContent).commitAllowingStateLoss();
    supportActionBar.setTitle(mContent.getMenuTitle());
}

Logcat:

03-20 02:41:07.190: E/AndroidRuntime(22735): FATAL EXCEPTION: main
03-20 02:41:07.190: E/AndroidRuntime(22735): Process: fr.free.ligol.realdebrid, PID: 22735
03-20 02:41:07.190: E/AndroidRuntime(22735): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
03-20 02:41:07.190: E/AndroidRuntime(22735):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at java.util.ArrayList.set(ArrayList.java:481)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.support.v4.app.FragmentManagerImpl.makeInactive(FragmentManager.java:1158)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.support.v4.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1201)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:639)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.os.Handler.handleCallback(Handler.java:733)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.os.Handler.dispatchMessage(Handler.java:95)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.os.Looper.loop(Looper.java:136)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at android.app.ActivityThread.main(ActivityThread.java:5017)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at java.lang.reflect.Method.invoke(Native Method)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-20 02:41:07.190: E/AndroidRuntime(22735):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
like image 975
Ligol Avatar asked Mar 20 '14 01:03

Ligol


1 Answers

You are using Fragment list like :

FragmentList.findFragmentById(0);

And at the index 0 there is no fragment added so it is showing outOFBoundsException.

Check the list size and then retrieve the data from the list.

like image 82
Arun kumar Avatar answered Sep 19 '22 11:09

Arun kumar