我正在尝试将日期转换为String,但它给了我一个 java.lang.IndexOutOfBoundsException ,我真的不知道为什么。 我的代码: `
DateFormat df = new SimpleDateFormat("HH:mm");
String tempStartTime =df.format(currentAgenda.getFestivals().get(0).getFestivalBeginTime());
String tempEndTime = df.format(currentAgenda.getFestivals().get(0).getFestivalEndTime());`
当我尝试运行程序时,它给了我这些错误:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at AgendaGUI.createAndShowGUIMenuBar(AgendaGUI.java:152)
at AgendaGUI.<init>(AgendaGUI.java:79)
at AgendaGUI$8.run(AgendaGUI.java:706)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
方法getFestivalBeginTime和getFestivalEndTime都返回一个Date对象,所以我不明白为什么这应该是错的? 提前谢谢!