获取exceptionIndexOutOfBoundsException FragmentManagerImpl后分享的东西到应用程序

我刚刚分享内容到我的应用程序,只是在应用程序已经启动的情况下,我得到这个exception。 如果我直接启动应用程序,所有的东西都很好。 如果我分享了一些东西给我的应用程序,并且应用程序还没有运行,所有的东西都可以正常工作 在第一种情况下他们不工作。

@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) 

Solutions Collecting From Web of "获取exceptionIndexOutOfBoundsException FragmentManagerImpl后分享的东西到应用程序"

您正在使用片段列表,如:

 FragmentList.findFragmentById(0); 

并且在索引0处没有添加片段,因此它显示了outBoundsException。

检查列表大小,然后从列表中检索数据。