我有一个显示如下的代码。但是它有错误,显示为“错误线”。错误消息是:
java.lang.NoClassDefFoundError:ParseException。
有人可以帮助我解决该错误吗?非常感谢!
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.*;
public class TestCalendar2 {
public static void main(String[] args) throws ParseException{ // error line
String str = "2020-10-10";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("df:" + df);
Date date = df.parse(str);
System.out.println("date:" + date);
Calendar c = new GregorianCalendar();
System.out.println("c:" + c);
c.setTime(date);
System.out.println("Sunday\t一\t二\t三\t四\t五\t六");
c.set(Calendar.DAY_OF_MONTH,1);
for(int i = 0; i < c.get(Calendar.DAY_OF_WEEK)-1;i++) {
System.out.print("\t");
}
for (int i=1; i<=c.getActualMaximum(Calendar.DATE); i++) {
System.out.print(c.get(Calendar.DAY_OF_MONTH)+"\t");
if(c.get(Calendar.DAY_OF_WEEK)== Calendar.SATURDAY) {
System.out.println();
}
c.add(Calendar.DAY_OF_MONTH, 1);
}
}
}
答案 0 :(得分:1)
您需要导入它:
import java.text.ParseException;