大家好,我試圖給JWindow添加一個可變長度的數組,但我得到一個運行時錯誤。想從這裏幫助..將可變長度的JRadioButtons數組添加到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[];
}
但我得到的錯誤是: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)
Hay Steltem請make這個程序工作。我嘗試了一切傢伙。 nt甚至在你的建議後工作... – Mavrick 2013-03-21 10:15:42