1
我有一個日期字符串:NumberFormatException異常:無法解析「」作爲整數
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"};
我遇到的問題是,當它是一個一個字月份名(即穆哈拉姆,薩法爾,拉賈布等)。一切工作順利。但是,如果這是一個帶有空格或短劃線的詞(即Rabi-al awwal,Dhul Hijjah),則會引發錯誤:NumberFormatException: unable to parse '' as integer
或NumberFormatException: unable to parse 'al' as integer
我在做什麼錯?
感謝指點出來。我刪除了's +'作爲空格,它工作。然而,還有什麼其他的解決方案能有如果我想分裂標記中的分隔符'-'的字符串,但也在月份名稱顯示呢? – input 2012-07-12 21:12:36