我有一个正常工作的代码,但有时(并非总是如此, Crashlytics )我正在执行NullPointerException
时获得getSerializableExtra(START_DATE)
。我总是把long
值放在那里,所以它不能为空。是否有可能丢失额外数据?
开始意图:
Intent intent = new Intent(getActivity(), UsersAroundEventOrHotelActivity.class);
intent.putExtra(UsersAroundEventOrHotelActivity.PLACE_ID, placeId);
intent.putExtra(UsersAroundEventOrHotelActivity.PLACE_TYPE, placeType);
intent.putExtra(UsersAroundEventOrHotelActivity.START_DATE, startDate.getTime());
intent.putExtra(UsersAroundEventOrHotelActivity.END_DATE, endDate.getTime());
使用onCreate
方法获取数据:
Long placeId = (Long) getIntent().getSerializableExtra(PLACE_ID);
PlaceType placeType = (PlaceType) getIntent().getSerializableExtra(PLACE_TYPE);
Date startDate = new Date((Long) getIntent().getSerializableExtra(START_DATE));
Date endDate = new Date((Long) getIntent().getSerializableExtra(END_DATE));
当我使用调试器进行尝试时,它就像魅力一样,但是有些用户在行NullPointerException
中获得了.getSerializableExtra(START_DATE)
任何想法?