Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Map compiler error

  1. #1
    Member
    Join Date
    Sep 2011
    Location
    Nanuet, NY USA
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Map compiler error

    Hi I am working on an example problem from the book that is not compiling correctly.

    Here is the compiler error:

    TestMap.java:6: type Map does not take parameters
    Map<String, Integer> hashMap = new HashMap<String, Integer>();
    TestMap.java:16: type Map does not take parameters
    Map<String, Integer> treeMap =
    ^
    TestMap.java:22: type Map does not take parameters
    Map<String, Integer> linkedHashMap =
    ^

    Here is the example code from the book:
     
    import java.util.*;
     
     
    public class TestMap {
      public static void main(String[] args) {
        Map<String, Integer> hashMap = new HashMap<String, Integer>();
        hashMap.put("Smith", 30);
        hashMap.put("Anderson", 31);
        hashMap.put("Lewis", 29);
        hashMap.put("Cook", 29);
     
        System.out.println("Display entries in a HashMap");
        System.out.println(hashMap);
     
        Map<String, Integer> treeMap = new TreeMap<String, Integer>(hashMap);
        System.out.println("Display entries in ascending order of key");
        System.out.println(treeMap);
     
        Map<String, Integer> linkedHashMap = new LinkedHashMap<String, Integer>(16, 0.75f, true);
        linkedHashMap.put("Smith", 30);
        linkedHashMap.put("Anderson", 31);
        linkedHashMap.put("Lewis", 29);
        linkedHashMap.put("Cook", 29);
     
        System.out.println("The age for " + "Lewis is " + linkedHashMap.get("Lewis").intValue());
     
        System.out.println("\nDisplay entries in a LinkedHashMap");
        System.out.println(linkedHashMap);
      } 
     
    }

    I'm not sure why Map doesn't take parameters when the book and the Java Tutorials site has an example using Map<K, V>. Any help would be appreciated.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Map compiler error

    hmm... odd. It works perfectly fine for me. Are you sure the source file is saved, and that you are indeed compiling against the correct source file? Also, what version of Java are you using?

  3. #3
    Member
    Join Date
    Sep 2011
    Location
    Nanuet, NY USA
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Map compiler error

    Quote Originally Posted by helloworld922 View Post
    hmm... odd. It works perfectly fine for me. Are you sure the source file is saved, and that you are indeed compiling against the correct source file? Also, what version of Java are you using?
    I've repeatedly saved the source file. I am using jdk1.6.0_01

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Map compiler error

    How are you compiling the program? Is there a Map.java file in the same directory?

  5. The Following User Says Thank You to helloworld922 For This Useful Post:

    kc120us (September 21st, 2011)

  6. #5
    Member
    Join Date
    Sep 2011
    Location
    Nanuet, NY USA
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Map compiler error

    Quote Originally Posted by helloworld922 View Post
    How are you compiling the program? Is there a Map.java file in the same directory?
    That is the problem. There is Map.java file in the source directory (completely different program). I got rid of that file and that fixed it.


    Thank you
    Casey

Similar Threads

  1. Creating a Compiler in Java
    By Superstar288 in forum Java Theory & Questions
    Replies: 20
    Last Post: February 22nd, 2013, 09:05 AM
  2. Java 6.0 Compiler Error
    By jilomes in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 19th, 2011, 05:34 PM
  3. Why the compiler can not find the symbol?
    By AlicNewbie in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2010, 08:16 PM
  4. setting the compiler for eclipse mac os x
    By etidd in forum Java IDEs
    Replies: 2
    Last Post: January 29th, 2010, 10:18 AM
  5. sql compiler
    By tsuki in forum JDBC & Databases
    Replies: 6
    Last Post: October 16th, 2009, 11:35 PM