CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Java hashmap help

    Hi guys I am trying to read a file of integers that is information about way points into a hashmap. This is what I have so far
    import java.io.*;
    import java.util.*;
    import java.util.HashMap;
    import java.util.Iterator;



    class Waypoints {
    public static void main(String[] args) throws FileNotFoundException {
    Scanner scanner = new Scanner(new FileReader("waypoints.txt"));


    HashMap<String, String> map = new HashMap<String, String>();

    while (scanner.hasNextInt()) {
    HashMap.put(scanner.nextInt());
    }

    System.out.println(map);
    }
    }

    when I try to compile I keep getting this error...

    Test.java:16: cannot find symbol
    symbol : method put(int)
    location: class java.util.HashMap
    HashMap.put(scanner.nextInt());

    Please help me resolve this or point me in the right direction I'm not even sure if I am on the right way of doing this.

    -Thanks

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java hashmap help

    Please use code tags when posting code.

    You have created an instance of HashMap but are then using the classname when calling put(). This means you are trying to call a static method called put() which the HashMap class doesn't have, hence the warning.

    Mind you there isn't an instance method called put() which only has one argument either. A mapping requires 2 arguments, the key and the value. Always read the Java Docs when using classes to make sure you using them correctly.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Jan 2011
    Posts
    24

    Re: Java hashmap help

    Also try to understand the Error so that you can solve it by yourself in future.

    Test.java:16: cannot find symbol ( this line says that problem is on line 16 on file Test.java)

    Can not find symbol means either variable, method or class whichever is on that line is not exists, this may be due to typo or anything else.

    these are the extra details

    symbol : method put(int)
    location: class java.util.HashMap


    here symbol is method put which takes an int argument and as said by Keang that doesn't exists.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured