Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在JPanel JPanel=jDayChooser1.getDayPanel()中获取NullPointerException_Java_Swing_Nullpointerexception_Calendar_Jdatechooser - Fatal编程技术网

Java 在JPanel JPanel=jDayChooser1.getDayPanel()中获取NullPointerException

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

在本文中,我试图从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 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();
}