これで、mysqlデータベースから日付を取得し、色を設定してそれらの日付をjDayChooserに表示しようとしていますJPanel jPanel = jDayChooser1.getDayPanel()
が、エラー「NullPointerException」を取得しています。
public Calender() {
// retrieving the dates from db
getDates c = new getDates();
Date[] a = c.Dates();
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
JPanel jPanel = jDayChooser1.getDayPanel();
Component component[] = jPanel.getComponents();
for(int i=0;i<a.length;i++) {
if(month == a[i].getMonth() && year == a[i].getYear()) {
component[ a[i].getDay()].setBackground(Color.blue);
}
}
initComponents();
}
ここにスタックトレースがあります...
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at greetingcard.Calender.<init>(Calender.java:37)
at greetingcard.Calender$1.run(Calender.java:100)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
BUILD SUCCESSFUL (total time: 5 seconds)