aspose file tools*
The moose likes Bunkhouse Porch and the fly likes Missing something Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Books » Bunkhouse Porch
Bookmark "Missing something" Watch "Missing something" New topic
Author

Missing something

Phil Kirsch
Greenhorn

Joined: Jun 14, 2006
Posts: 1
I got the code below from Head First Java, Edition 2, page 567.

1 import java.util.*;
2
3 public class TestMap {
4
5 public static void main(String[] args) {
6 HashMap<String, Integer> scores = new HashMap<String, Integer>();
7
8 scores.put("Kathy", 42);
9 scores.put("Bert", 343);
10 scores.put("Skyler", 420);
11
12 System.out.println(scores);
13 System.out.println(scores.get("Bert"));
14
15 }
16 }


I get the following errors at compile time:

javac map.java
map.java:6: not a statement
HashMap<String, Integer> scores = new HashMap<String, Integer>();
^
map.java:6: ';' expected
HashMap<String, Integer> scores = new HashMap<String, Integer>();
^
2 errors


I've checked my typing and gone back in the book. Can't figure out what's going on. I may feel really stupid when someone explains this, but right now I'm stumped.
Orem Hun
Greenhorn

Joined: May 24, 2005
Posts: 28
Which version of JDK are you using ?
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
the only reason that could happen is if the compiler doesn't know about the Collections framework.
That excludes every compiler from 1.2 onwards except gcj (which is a disaster, never use it!) AFAIK.


42
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Phil, it seems to me that even if you were using a JDK so old it did not recognize HashMap, you should get a different error message in that case:

TestMap.java:6: cannot find symbol
symbol : class HashMap

I think there's still a typo somewhere, perhaps in line 5. I suggest you copy and paste the code you're trying to compile. Don't insert line numbers - just copy exactly what you have.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Missing something