BadParcelableException:ClassNotFoundException在解组时:android.support.v4.app.FragmentManagerState [英] BadParcelableException:ClassNotFoundException when unmarshalling: android.support.v4.app.FragmentManagerState
问题描述
三天前我已经迁移到SDK Android 27.1.0,并且出现了类似这样的崩溃,我不明白为什么.它(当前)显示在Android 8和6上.
I've migrated to SDK Android 27.1.0 3 days ago, and there are some crashs like this one, I can't understand why. It appears (currently) on Android 8 and 6.
BadParcelableException ClassNotFoundException when unmarshalling: android.support.v4.app.FragmentManagerState android.support.v4.app.Fragment.setUserVisibleHint
android.os.Parcel.readParcelableCreator (Parcel.java:2916)
android.os.Parcel.readParcelable (Parcel.java:2842)
android.os.Parcel.readValue (Parcel.java:2745)
android.os.Parcel.readArrayMapInternal (Parcel.java:3114)
android.os.BaseBundle.initializeFromParcelLocked (BaseBundle.java:273)
android.os.BaseBundle.unparcel (BaseBundle.java:226)
android.os.BaseBundle.putBoolean (BaseBundle.java:532)
arrow_right
android.support.v4.app.Fragment.setUserVisibleHint (Fragment.java:960)
android.support.v4.app.FragmentStatePagerAdapter.instantiateItem (FragmentStatePagerAdapter.java:121)
android.support.v4.view.ViewPager.addNewItem (ViewPager.java:1004)
android.support.v4.view.ViewPager.populate (ViewPager.java:1218)
android.support.v4.view.ViewPager.populate (ViewPager.java:1086)
android.support.v4.view.ViewPager$3.run (ViewPager.java:267)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)
android.view.Choreographer.doCallbacks (Choreographer.java:723)
android.view.Choreographer.doFrame (Choreographer.java:655)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:897)
android.os.Handler.handleCallback (Handler.java:790)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:6494)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
这是我的适配器:
public abstract class CalendarPagerAdapter extends FragmentStatePagerAdapter {
private static final String TAG = LogUtils.makeLogTag(CalendarPagerAdapter.class);
protected DateTime mDateTime;
private final int mCount;
protected int mTodayPosition;
public static class CalendarContext {
public int mRange; // range = nb of days supported
public int mTodayPosition; // Today index in this area
public int mCurrentWeek; // Week number of today
public DateTime mFrom, mTo; // Compute from and to datetimes
public boolean mIsSundayFirstDay;
public CalendarContext(int area, int todayPosition, DateTime from, DateTime to,
int currentWeek, boolean isSundayFirstDay) {
mRange = area;
mTodayPosition = todayPosition;
mFrom = from;
mTo = to;
mCurrentWeek = currentWeek;
mIsSundayFirstDay = isSundayFirstDay;
}
}
public static CalendarContext computeAreaAndTodayPosition(int initialArea, int initialTodayPosition) {
// Compute min / max dates from now
DateTime from = new DateTime().minusDays(initialArea - initialTodayPosition).dayOfWeek().withMinimumValue();
DateTime to = new DateTime().plusDays(initialTodayPosition).dayOfWeek().withMaximumValue();
boolean isSundayFirstDay = false;
Calendar calendar = Calendar.getInstance(CompatUtils.getLocale(false));
if (calendar.getFirstDayOfWeek() == Calendar.SUNDAY) {
isSundayFirstDay = true;
from = from.minusDays(1);
to = to.minusDays(1);
}
LogUtils.LOGD("XXXX", "from dt=" + from.toString());
LogUtils.LOGD("XXXX", "to dt=" + to.toString());
// Compute nb days area supported
int daysRange = daysBetween(from, to).getDays() + 1;
LogUtils.LOGD("XXXX", "daysRange=" + daysRange);
// Compute today position
int todayPosition = daysBetween(from, DateTime.now().withTimeAtStartOfDay()).getDays() + 1;
LogUtils.LOGD("XXXX", "todayPosition=" + todayPosition);
int currentWeek = DateTime.now().getWeekOfWeekyear() - from.getWeekOfWeekyear();
LogUtils.LOGD("XXXX", "currentWeek=" + currentWeek);
return new CalendarContext(daysRange, todayPosition, from, to, currentWeek, isSundayFirstDay);
}
public CalendarPagerAdapter(FragmentManager mgr, int count, int todayPosition) {
super(mgr);
mDateTime = DateTime.now();
mCount = count;
mTodayPosition = todayPosition;
}
@Override
public int getCount() {
return mCount;
}
public boolean isTodayPosition(int position) {
return computeDifferenceDays(position) == 0;
}
public boolean isPastPosition(int position) {
return computeDifferenceDays(position) < 0;
}
public boolean isFuturPosition(int position) {
return computeDifferenceDays(position) > 0;
}
protected int computeDifferenceDays(int position) {
return position - getCalendarTodayPosition();
}
public long convertPositionToMs(int position) {
return convertPositionToMs(mDateTime, position);
}
public long convertMinPositionToMs() {
return convertPositionToMs(mDateTime, 0);
}
public long convertMaxPositionToMs() {
return convertPositionToMs(mDateTime, mCount - 1);
}
public String convertPositionToDate(int position) {
return TimeUnits.dateTimeToDateServer(new DateTime(convertPositionToMs(position)));
}
public long convertPositionToMs(DateTime datime, int position) {
int dayNum = computeDifferenceDays(position);
if (dayNum < 0)
return datime.minusDays(Math.abs(dayNum)).getMillis();
else if (dayNum > 0)
return datime.plusDays(Math.abs(dayNum)).getMillis();
else
return datime.getMillis();
}
public int convertMsToPosition(long millis) {
DateTime dtReceived = new DateTime(millis).withTimeAtStartOfDay();
return convertDateTimeToPosition(dtReceived);
}
public int convertDateTimeToPosition(DateTime dtReceived) {
DateTime now = DateTime.now().withTimeAtStartOfDay();
int nbDays = daysBetween(now, dtReceived).getDays();
return getCalendarTodayPosition() + nbDays;
}
public int getCalendarTodayPosition() {
return mTodayPosition;
}
public void shiftWithOffset(WeekDatePicker weekDatePicker, TextView weekDatePickerDayTextView,
DateTime currentSelectedDate, int offset) {
if (offset < 0 && mTodayPosition > 0) mTodayPosition += offset;
mDateTime = DateTime.now();
weekDatePicker.refreshTodayPosition();
weekDatePickerDayTextView.setText(TimeUnits.dateTimeToString(
currentSelectedDate, true, true, true, true, true));
}
}
您有一些想法可以解决此问题吗?
Have you got some ideas guys to fix this problem?
非常感谢!
推荐答案
@XJIOP说的是正确的,我在生产中也遇到了同样的问题,但是我找不到崩溃的原因,我遵循@XJIOP路径并产生了错误,我通过更新精简版解决了该错误来自
@XJIOP said is correct i also have same issue on my production, but i was unable to find what the crash, i followed @XJIOP path and produce the bug,i resolved the bug by updating the compact version from
appcompat 27.1.0至27.1.1
appcompat 27.1.0 to 27.1.1
因为我使用的是proguard,所以我还在proguard中添加了以下行
since i am using proguard i also added the following line to my proguard
如果在生产版本上使用proguard,则将以下行添加到proguard,否则忽略
add the following line to proguard if you are using proguard on your production build else ignore
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
添加专业防护线并更新了压缩库之后,我得以解决该问题,并且在更新后的生产版本中仍报告了该错误.希望这对其他人有帮助
After adding the pro guard line and updating the compact lib i was able to fix the issue and the bug hasent reported yet on my updated production build. hope this will help some others
这篇关于BadParcelableException:ClassNotFoundException在解组时:android.support.v4.app.FragmentManagerState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!