我突然得到了这个错误 在那之前它工作得很好,..
我的日期格式" 2014年9月11日下午3:31"
public boolean validateLuckyDrawExpirationDate(String strExpirationDate) throws Exception{
SimpleDateFormat df=new SimpleDateFormat("MMM dd yyyy hh:mmaa");
Date expirationDateObj=df.parse(strExpirationDate);
Date today=new Date();
boolean isAfter=today.after(expirationDateObj);
boolean isBefore=today.before(expirationDateObj);
Log.v("isToday", String.valueOf(isAfter));
Log.v("isBefore", String.valueOf(isBefore));
Log.v("Original date", String.valueOf(expirationDateObj));
Log.v("SimpleDateFormat", String.valueOf(df.format(expirationDateObj)));
Log.e("startDate...2",strExpirationDate);
return isBefore;
}
答案 0 :(得分:1)
正如您的问题标题所示,您正在解析null
此方法。这样unparseable date:“null”
就会因此而得到。
此方法对Sep 11 2014 3:31PM
答案 1 :(得分:1)
您确定要使用参数值validateLuckyDrawExpirationDate()
调用方法Sep 11 2014 3:31PM
吗?
尝试将代码放入try-catch
块:
public boolean validateLuckyDrawExpirationDate(String strExpirationDate) throws Exception{
Boolean isBefore = false;
try{
SimpleDateFormat df=new SimpleDateFormat("MMM dd yyyy hh:mmaa");
Date expirationDateObj=df.parse(strExpirationDate);
Date today=new Date();
boolean isAfter=today.after(expirationDateObj);
isBefore=today.before(expirationDateObj);
Log.v("isToday", String.valueOf(isAfter));
Log.v("isBefore", String.valueOf(isBefore));
Log.v("Original date", String.valueOf(expirationDateObj));
Log.v("SimpleDateFormat", String.valueOf(df.format(expirationDateObj)));
Log.e("startDate...2",strExpirationDate);
}
catch (ParseException e) {
Toast.makeText(getApplicationContext(), "Date is not valid!",
Toast.LENGTH_LONG).show();
}
return isBefore;
}