Student needs help with Date() in Windows.
Hi all. I am newbie to Java and try a test:
import javax.swing.*; // for JFrame and JOptionPane
import java.util.*;// for Date
import java.text.*;// for SimpleDateFormat
class MyDate {
static public void main (String[] args) {
JFrame mywindow;
mywindow = new JFrame();
mywindow.setSize(500,500);
mywindow.setTitle("Using the SimpleDateFormat Class ");
mywindow.setVisible(true);
Date now = new Date();
//SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, yyyy");
SimpleDateFormat sdf = new SimpleDateFormat();
JOptionPane.showMessageDialog(mywindow, "Today is " + sdf.format(now));
}
}
It works on a Linux machine, but gives me this error in Windows (two different windows machines).
init:
deps-jar:
compile-single:
run-single:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:281)
at java.text.Format.format(Format.java:140)
at MyDate.main(MyDate.java:20)
Since I am a student, I really would appreciate any help as soon as possible. I get graded on this Monday.
thx, Tom

