Android getSerializableExtra返回null

时间:2015-07-08 14:10:50

标签: java android android-intent

我有一个正常工作的代码,但有时(并非总是如此, 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)任何想法?

0 个答案:

没有答案