
I have three combo boxes
First combo box display the year
Second combo box display the month for the selected year.
Third combo box display number of week in a selected month for the year.
I am select year, month and the third combo box display the number of week. If i select any one week then some exception thrown.
Ex.
Exception in thread "AWT - EventQueue-0" java.lang.NullPointerException atLabour_weekly. itemStateChanged.
My Sample code.
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource() == cmbyear)
{
year=cmbyear.getSelectedItem().toString();
//cmbmonth.setEnabled(true);
}
else if(ie.getSource() == cmbmonth)
{
if(!(cmbmonth.getSelectedItem().equals("Select")))
{
month=cmbmonth.getSelectedItem().toString();
Calendar ca1 = Calendar.getInstance();
int y=Integer.parseInt(year);
int m = Integer.parseInt(month)-1;
ca1.set(y,m,1);
int days = ca1.getActualMaximum(Calendar.DAY_OF_MONTH);
cmbweek.removeAllItems();
cmbweek.addItem("Select");
java.util.Date date;
int j=1;
for(int i=1;i<=days;i++)
{
date=(new GregorianCalendar(y,m,i)).getTime();
SimpleDateFormat f = new SimpleDateFormat("EEEE");
String day=f.format(date);
if(day.equals("Saturday"))
{
cmbweek.addItem(j+" Week");
j++;
}
}
}
}
else if(ie.getSource() == cmbweek)
{
System.out.println("Hai");
if(!(cmbweek.getSelectedItem().equals("Select")))
{
System.out.println(cmbweek.getSelectedItem().toString());
}
}
}
Please Any one help me as soon as possible.