我有一个日期字符串:
gridcell.setTag(theday + "-" + themonth + "-" + theyear + "|" + hijri_day + "-" + hijri_month + " ("+ hijri_monthno +") " + hijri_year);
..如果日期有事件,我会在按钮单击时将其传递给另一个类:
String date_month_year = (String) view.getTag();
if (isHoliday(d, m, y))
{
Intent i = new Intent(view.getContext(), Events.class);
i.putExtra("date_string", date_month_year);
startActivity(i);
}
在 Events.class 中,我得到了参数:
Intent intent = getIntent();
String date_string = intent.getStringExtra("date_string");
date_view = (TextView) this.findViewById(R.id.hijridate);
eventdetails = (TextView) this.findViewById(R.id.eventdetails);
date_view.setText(date_string);
String[] dateAr = date_string.split("-|\\||\\(|\\)|\\s+");
m = Integer.parseInt(dateAr[6]);
d = Integer.parseInt(dateAr[3]);
y = Integer.parseInt(dateAr[8]);
这是回历月份数组:
private String months[] = {"Muharram","Safar","Rabi-al Awwal","Rabi-al Thani","Jumada al-Ula","Jumada al-Thani","Rajab","Sha\'ban","Ramadhan","Shawwal","Dhul Qa\'dah","Dhul Hijjah"};
我遇到的问题是,当它是一个单词的月份名称(即 Muharram、Safar、Rajab 等)时,一切都很顺利。但是,如果它是带有空格或破折号的单词(即 Rabi-al awwal、Dhul Hijjah),则会引发错误:NumberFormatException: unable to parse '' as integer
或NumberFormatException: unable to parse 'al' as integer
我究竟做错了什么?