Java 在JPanel JPanel=jDayChooser1.getDayPanel()中获取NullPointerException
在本文中,我试图从mysql数据库中获取日期,并通过设置颜色在jDayChooser中显示这些日期Java 在JPanel JPanel=jDayChooser1.getDayPanel()中获取NullPointerException,java,swing,nullpointerexception,calendar,jdatechooser,Java,Swing,Nullpointerexception,Calendar,Jdatechooser,在本文中,我试图从mysql数据库中获取日期,并通过设置颜色在jDayChooser中显示这些日期 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
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();
}
公共日历(){
//从数据库中检索日期
getDates c=新的getDates();
日期[]a=c.日期();
Calendar cal=Calendar.getInstance();
int day=cal.get(日历日/月日);
int month=cal.get(日历月);
int year=cal.get(日历年);
JPanel JPanel=jDayChooser1.getDayPanel();
Component Component[]=jPanel.getComponents();
对于(int i=0;我找到了它,找到了它:)
公共日历(){
初始化组件();
//从数据库中检索日期
getDates c=新的getDates();
日期[]a=c.日期();
Calendar cal=Calendar.getInstance();
int day=cal.get(日历日/月日);
int month=cal.get(日历月);
int year=cal.get(日历年);
JPanel JPanel=jDayChooser1.getDayPanel();
Component Component[]=jPanel.getComponents();
对于(int i=0;iAdd你的堆栈跟踪。我添加了堆栈跟踪:)你在哪里创建jDayChooser1
?它在我创建的jFrame中。它有什么区别吗?看起来jDayChooser1在那一点上是空的。你如何/在哪里创建它?
public Calender() {
initComponents();
// 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();
}