在Volley中获取服务器日期时出现空指针异常

时间:2016-03-04 09:06:24

标签: android date exception caching android-volley

获取缓存的服务器日期时,我得到Null Pointer Exception。我找不到相关的解决方案。

这是我的logcat

03-04 14:27:13.960: E/AndroidRuntime(19261): FATAL EXCEPTION: main
03-04 14:27:13.960: E/AndroidRuntime(19261): Process: com.****, PID: 19261
03-04 14:27:13.960: E/AndroidRuntime(19261): java.lang.NullPointerException: Attempt to read from field 'long com.android.volley.Cache$Entry.serverDate' on a null object reference
03-04 14:27:13.960: E/AndroidRuntime(19261): at com.****.FragmentSpecificRestaurant.onCreateView(FragmentSpecificRestaurant.java:170)

这是我的简单代码

    Calendar calendar = Calendar.getInstance();
    long serverDate = MyApplication.getInstance().getRequestQueue().getCache().get(url_Getcategory).serverDate;
    if (Utils.getMinutesDifference(serverDate, calendar.getTimeInMillis()) >= 30) {

                MyApplication.getInstance().getRequestQueue().getCache().remove(url_Getcategory);
    }

0 个答案:

没有答案