-
Identifier expected
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>
-
Re: Identifier expected
where is currentLocale defined?
"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>
-
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>
-
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>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks