如果我对应用程序进行后台处理并在一段时间后恢复它,则会收到以下异常.
如果我改变方向或背景并立即恢复应用程序(在两种情况下都执行onSaveInstanceState和onCreate),那么savedInstanceState Bundle包含正确的ArrayList,一切正常.
02-05 14:42:06.254 E/AndroidRuntime(24355):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.savant.donordetailsvIEwpagerTitle/com.savant.donordetailsvIEwpagerTitle.activitIEs.DonorDetailsContainerFragmentActivity}:
java.lang.NullPointerException: expected receiver of type
com.savant.donordetailsvIEwpagerTitle.activitIEs.DonorDetailsContainerFragmentActivity$RunningLoadersList,
but got null
private class RunningLoadersList extends ArrayList<RunningLoader> implements Parcelable { private static final long serialVersionUID = 663585476779879096L; public RunningLoadersList() { } @SuppressWarnings("unused") public RunningLoadersList(Parcel in) { this(); readFromParcel(in); } private voID readFromParcel(Parcel in) { this.clear(); // First we have to read the List size int size = in.readInt(); for (int i = 0; i < size; i++) { RunningLoader r = new RunningLoader(in.readInt(), in.readBundle()); this.add(r); } } public int describeContents() { return 0; } public final Parcelable.Creator<RunningLoadersList> CREATOR = new Parcelable.Creator<RunningLoadersList>() { public RunningLoadersList createFromParcel(Parcel in) { return new RunningLoadersList(in); } public RunningLoadersList[] newArray(int size) { return new RunningLoadersList[size]; } }; public voID writetoParcel(Parcel dest, int flags) { int size = this.size(); // We have to write the List size, we need him recreating the List dest.writeInt(size); for (int i = 0; i < size; i++) { RunningLoader r = this.get(i); dest.writeInt(r.ID); dest.writeBundle(r.args); } }}static final class RunningLoader { private final int ID; private final Bundle args; RunningLoader(int _ID, Bundle _args) { ID = _ID; args = _args; }} @OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // This has to be called before setContentVIEw and you must use the // class in androID.support.v4.vIEw and NOT androID.vIEw requestwindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentVIEw(R.layout.main); Log.d(LOG_TAG, "onCreate"); mAdapter = new VIEwPagerTitleAdapter(getSupportFragmentManager()); mPager = (VIEwPager) findVIEwByID(R.ID.pager); mPager.setAdapter(mAdapter); TabPageIndicator indicator = (TabPageIndicator) findVIEwByID(R.ID.tabindicator); indicator.setVIEwPager(mPager); // first check if we already have a running loader if ((savedInstanceState != null) && savedInstanceState.containsKey("RUNNING_LOADERS")) { mRunningLoaders = savedInstanceState.getParcelable("RUNNING_LOADERS"); } if (mRunningLoaders == null) { mRunningLoaders = new RunningLoadersList(); } if (mRunningLoaders != null) { for (int i = 0; i < mRunningLoaders.size(); i++) { StartLoader(mRunningLoaders.get(i).ID, mRunningLoaders.get(i).args); } } if (getSupportLoaderManager().hasRunningLoaders()) { setProgressbarIndeterminateVisibility(Boolean.TRUE); } else { setProgressbarIndeterminateVisibility(Boolean.FALSE); }} @OverrIDeprotected voID onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable("RUNNING_LOADERS", mRunningLoaders); Log.d(LOG_TAG, "onSaveInstanceState");}
解决方法:
Parcelable.Creator< RunningLoadersList>()必须是这样的静态
public static final Parcelable.Creator<RunningLoadersList> CREATOR = new Parcelable.Creator<RunningLoadersList>() {.......}
总结 以上是内存溢出为你收集整理的android – FragmentActivity NullPointer在onCreate savedInstanceState Bundle中全部内容,希望文章能够帮你解决android – FragmentActivity NullPointer在onCreate savedInstanceState Bundle中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)