JLabel 배열이 있는데, 작동하는 것 같습니다. System.out.print (days [index]); 나는 실제 정보가 포함되어 있고 라벨이 있고 작동합니다.Java의 단일 패널에 JLabel 배열 추가?
패널에 어떤 인덱스에서나 레이블을 추가하려고하면 널 포인터 예외가 발생하며 그 이유를 모르겠습니다.
public class DrawCalendar extends JPanel{
private JLabel month = new JLabel("Month");
private JLabel[] days = {
new JLabel("Sunday"),
new JLabel("Monday"),
new JLabel("Tuesday"),
new JLabel("Wednesday"),
new JLabel("Thursday"),
new JLabel("Friday"),
new JLabel("Saturday")
};
private JPanel dayBoxes;
private JPanel topLabels;
public DrawCalendar(int month){
topLabels.add(days[1]); //the NullPointerException caused here
add(topLabels);
}
}
* 마른 세수 * 감사 – leigero