This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Gregg Williams

Greenhorn
+ Follow
since Oct 11, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gregg Williams

Many thanks from a beginner for both answers! --gw
13 years ago
I'm using the latest version of Groovy (1.5.7). I was using Groovy to learn about formatting strings, and I was getting error messages were I shouldn't have. I searched the Internet for an answer, but I didn't find anything.

Here's some code from Sun's Java 1.5 doc pages; it works just as you would expect it in Java:

-----------------------------------------
import java.util.Calendar;
import java.util.GregorianCalendar;
import static java.util.Calendar.*;

public class Scratch {

public static void main(String[] args) {
Calendar c = new GregorianCalendar(1995, MAY, 23);
String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
System.out.println(s);
// -> prints "Duke's Birthday: 5 23, 1995"
}
}
-----------------------------------------

Here's the code that I put into the GroovyConsole window:

-----------------------------------------
import java.util.Calendar;
import java.util.GregorianCalendar;
import static java.util.Calendar.*;
Calendar c = new GregorianCalendar(1995, MAY, 23);
String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
System.out.println(s);

... and here's the output:

Exception thrown: groovy.lang.MissingPropertyException: No such property: tm for class: Script4

groovy.lang.MissingPropertyException: No such property: tm for class: Script4
at Script4.run(Script4:5)
-----------------------------------------

If you take out the import statements, you get a different error:

Exception thrown: groovy.lang.MissingPropertyException: No such property: MAY for class: Script5

groovy.lang.MissingPropertyException: No such property: MAY for class: Script5
at Script5.run(Script5:1)
-----------------------------------------

Any ideas why this is happening? Thanks.
13 years ago