Angelababy2018
Angelababy2018

Reputation: 43

How to fix "ParseException cannot be resolved to a type"?

I have a code which is shown as follows. But it has error, which is indicated as "error line". The error message is:

java.lang.NoClassDefFoundError: ParseException.

Can anyone help me fix the error? Thank you so much!

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);
        }
    }
}

Upvotes: 0

Views: 3183

Answers (1)

xingbin
xingbin

Reputation: 28279

You need import it:

import java.text.ParseException;

Upvotes: 3

Related Questions