这是我写的显示某月日历的程序,调试通过,但是运行时总是出现"Exception in thread "main" java.lang.NullpointerException"
import java.util.*;
public class MonthCalendar
{
private static Year year = new Year();
public MonthCalendar()
{
}
private static Calendar cal;
private String log[]={"日","一","二","三","四","五","六"};
public void show(int objYear, int objMonth)
{
cal.set(objYear, objMonth, 1);
int days = 0;
int dayOfWeek = 0;
if (year.isLeapYear(objYear))
{
if (objMonth == 2)
{
days = year.getDaysOfMonth(objMonth) + 1;
dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
}
}
for ( int i = 0 ; i < 7 ; i++ )
{
System.out.print("\t"+log[i]);
}
System.out.println();
for (int j = 1 ; j <= days ; j++ )
{
for (int i = 0 ; i < dayOfWeek ; i++ )
{
System.out.print("\t");
}
System.out.print("\t"+j);
int flag = dayOfWeek;
flag++;
if (flag % 7 == 0)
{
System.out.println();
}
}
}
public static void main(String[] args)
{
MonthCalendar mc = new MonthCalendar();
int objYear = Integer.parseInt(args[0]);
int objMonth = Integer.parseInt(args[1]);
mc.show(objYear, objMonth);
}
}
[此贴子已经被作者于2006-12-18 12:02:04编辑过]