在黑莓中向日历添加日历事件时显示非法状态异常

时间:2011-12-30 10:47:42

标签: blackberry

在我的应用程序中,它必须在日历中添加提醒,我已经使用黑莓事件实现了这一点,但它正在抛出非法状态异常。这是我实现的代码。请看看这个,并帮助我解决这个问题。

EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);
BlackBerryEvent bbEvent = (BlackBerryEvent) eventList.createEvent();

long sDate ;
long eDate ;
Date date;
date = new Date(HttpDateParser.parse("Dec 26, 2011"));
sDate = date.getTime();
date = new Date(HttpDateParser.parse("Dec 31, 2011"));
eDate = date.getTime();
bbEvent.addString(Event.SUMMARY, PIMItem.ATTR_NONE, subject);
bbEvent.addString(Event.LOCATION, PIMItem.ATTR_NONE, location);
bbEvent.addString(Event.NOTE, PIMItem.ATTR_NONE, description);
bbEvent.addDate(Event.START, PIMItem.ATTR_NONE, sDate);
bbEvent.addDate(Event.END, PIMItem.ATTR_NONE, eDate);
bbEvent.commit();

1 个答案:

答案 0 :(得分:2)

EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);// 1st Change
BlackBerryEvent bbEvent = (BlackBerryEvent) eventList.createEvent();

long sDate ;
long eDate ;
Date date;
date = new Date(HttpDateParser.parse("2011-12-26"));// 2nd    Use "yyyy-MM-dd" format 
sDate = date.getTime();
date = new Date(HttpDateParser.parse("2011-12-31"));// 3rd
eDate = date.getTime();
bbEvent.addString(Event.SUMMARY, PIMItem.ATTR_NONE, subject);
bbEvent.addString(Event.LOCATION, PIMItem.ATTR_NONE, location);
bbEvent.addString(Event.NOTE, PIMItem.ATTR_NONE, description);
bbEvent.addDate(Event.START, PIMItem.ATTR_NONE, sDate);
bbEvent.addDate(Event.END, PIMItem.ATTR_NONE, eDate);


eventList .commit();//4th change

检查一下,我在代码中进行了4次更改。