File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Missing something

 
Phil Kirsch
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of JDK are you using ?
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic