Issue:
CalendarTest.java:9: error: cannot find symbol
int today = d.get(Calendar.DAY_OF_MONTH);
^
symbol: method get(int)
location: variable d of type GregorianCalendar
My code:
import java.util.*;
public class CalendarTest
{
public static void main(String[] args)
{
GregorianCalendar d = new GregorianCalendar();
int today = d.get(Calendar.DAY_OF_MONTH);
}
}
So, what I've done so far was checking the API (methods get and set won't work at all). I've also been searching stackoverflow and google to get some help about the issue, but without any positive results.
Tried switching between Java 6 and Java 7 without any result at all. Been doing this for Calendar instead of GregorianCalendar, but the problem still remains.
I'm operating on Ubuntu 12.04. I've no clue what's wrong since those methods are included in GregorianCalendar class (as far as API says so)
Also,
CalendarTest.java:8: error: constructor GregorianCalendar in class GregorianCalendar cannot be applied to given types;
GregorianCalendar asd = new GregorianCalendar(2000, 10, 25);
^
required: no arguments
found: int,int,int
reason: actual and formal argument lists differ in length
won't work as well. It says that parameters (int, int, int) are wrong. Well it shouldn't, should it?
Please help me get past this, since I can not move any further (doing Core JAVA 2 Basics)
The code you've posted is fine. I strongly suspect you've got another class called GregorianCalendar
on your classpath. I suggest you look for it and remove it. Note that Calendar.DAY_OF_MONTH
itself appears to be found correctly.
One thing you might want to try (just to see which package is at fault) is explicitly specifying the types:
java.util.GregorianCalendar d = new java.util.GregorianCalendar();
int today = d.get(java.util.Calendar.DAY_OF_MONTH);
I suspect that will work, in which case you should look for a GregorianCalendar
type in the default package.
If that's still not working, it suggests your Java installation is broken.