大家好,我试图向 JWindow 添加一个可变长度的数组,但我遇到了运行时错误。需要这里的帮助..
这是我的代码:
package components;
import java.util.Calendar;
public class FullDay extends javax.swing.JWindow {
public FullDay() {
initComponents();
}
private void initComponents() {
int i;
//to get the no of days of the current month.
Calendar cal = Calendar.getInstance();
int maxdays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
getContentPane().setLayout(new java.awt.FlowLayout());
//Creating an array of radiobuttons having size equal to the no of days of the current //month
for(i=0; i<maxdays; i++) {
jRadioButton[maxdays] = new javax.swing.JRadioButton();
getContentPane().add(jRadioButton[i]);
}
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FullDay().setVisible(true);
}
});
}
private javax.swing.JRadioButton jRadioButton[];
}
但我得到的错误是:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at components.FullDay.initComponents(FullDay.java:18)
at components.FullDay.<init>(FullDay.java:8)
at components.FullDay$1.run(FullDay.java:30)
at java.awt.event.InvocationEvent.dispatch(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)