"Laran Coates" <lcoates@cyzygy.com> wrote in message
news:397dd333$1@news.devx.com...
>
> What does an identifier expected error usually mean?
> My code is below. It looks like it should work but I get the error below
> the code when I run it.
>
> <snippet>
> import java.util.Calendar;
> import java.text.DateFormat;
>
> public class CzgCalendar {
>
> Date theDate = new Date();
> DateFormat theDateFormat =
DateFormat.getDateTimeInstance(DateFormat.FULL,
> DateFormat.FULL, currentLocale);
> String dateOut = theDateFormat.format(theDate);
>
> System.out.println(dateOut);
>
> }
> </snippet>
>
> <error>
> CzgCalendar.java:12: Identifier expected.
> dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,
> ^
> 1 error
> </error>
07-26-2000, 11:02 AM
Paul Clapham
Re: Identifier expected
It means that "System.out..." should be inside a method or a constructor.
Your class code should be organized something like this:
public class Whatever {
... static and instance variables for the class...
... constructors for the class...
... methods for the class...
}
All of those three ...groups... are optional. In your case, when the
compiler encountered "System.out..." without first encountering the code
starting a constructor or a method, it decided you were still defining
variables.
Laran Coates <lcoates@cyzygy.com> wrote in message
news:397dd333$1@news.devx.com...
>
> What does an identifier expected error usually mean?
> My code is below. It looks like it should work but I get the error below
> the code when I run it.
>
> <snippet>
> import java.util.Calendar;
> import java.text.DateFormat;
>
> public class CzgCalendar {
>
> Date theDate = new Date();
> DateFormat theDateFormat =
DateFormat.getDateTimeInstance(DateFormat.FULL,
> DateFormat.FULL, currentLocale);
> String dateOut = theDateFormat.format(theDate);
>
> System.out.println(dateOut);
>
> }
> </snippet>
>
> <error>
> CzgCalendar.java:12: Identifier expected.
> dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,
> ^
> 1 error
> </error>
07-31-2000, 02:55 PM
Marc
Re: Identifier expected
It seems to me that the error is on dateFormatter. There is no variable declared
as dateFormatter but only as theDateFormat. If it is a static method it
must be accessed via it's class name. Alternatively, if it is a class you
must assign a variable name to instantiate the class.
Marc
"Paul Clapham" <pclapham@core-mark.com> wrote:
>It means that "System.out..." should be inside a method or a constructor.
>Your class code should be organized something like this:
>
>public class Whatever {
> ... static and instance variables for the class...
> ... constructors for the class...
> ... methods for the class...
>}
>
>All of those three ...groups... are optional. In your case, when the
>compiler encountered "System.out..." without first encountering the code
>starting a constructor or a method, it decided you were still defining
>variables.
>
>Laran Coates <lcoates@cyzygy.com> wrote in message
>news:397dd333$1@news.devx.com...
>>
>> What does an identifier expected error usually mean?
>> My code is below. It looks like it should work but I get the error below
>> the code when I run it.
>>
>> <snippet>
>> import java.util.Calendar;
>> import java.text.DateFormat;
>>
>> public class CzgCalendar {
>>
>> Date theDate = new Date();
>> DateFormat theDateFormat =
>DateFormat.getDateTimeInstance(DateFormat.FULL,
>> DateFormat.FULL, currentLocale);
>> String dateOut = theDateFormat.format(theDate);
>>
>> System.out.println(dateOut);
>>
>> }
>> </snippet>
>>
>> <error>
>> CzgCalendar.java:12: Identifier expected.
>> dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,
>> ^
>> 1 error
>> </error>
>
>