Java: Error parse date's string to date object : <p>I try to convert string to date on java. I read and try the example from this website <a href="https://www.mkyong.com/java/java-date-and-calendar-examples/" rel="nofollow">"Java Date and Calendar examples"</a> but I still cannot compile and run it. </p>

<p>This is my code.</p>

<pre><code>package javaapplication5;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class JavaApplication5 {   

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
        String dateInString = "31-08-1982 10:20:56";
        Date date = sdf.parse(dateInString);
        System.out.println(date);
    }

}
</code></pre>

<p>And I got this error.</p>

<pre><code>Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception java.text.ParseException; must be caught or declared to be thrown
</code></pre>

<p>What I missing or do it wrong? Thank you for help.</p>
