Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Cannot find symbol error on Map, HashMap

I'm trying to run this code:

import java.util.*;

public class ScanReg {
  public Map<Integer, ArrayList<Long>> scanMap = new HashMap<Integer, ArrayList<Long>>();
}

within this class:

import java.util.*;

public class NxtStart {
  ScanReg sr = new ScanReg();
}

This keeps giving me the following error:

.\ScanReg.java:6: error: cannot find symbol
        public Map<Integer, ArrayList<Long>> scanMap = new HashMap<Integer, Arra
yList<Long>>();
               ^
  symbol:   class Map
  location: class ScanReg
.\ScanReg.java:6: error: cannot find symbol
        public Map<Integer, ArrayList<Long>> scanMap = new HashMap<Integer, Arra
yList<Long>>();
                                                           ^
  symbol:   class HashMap
  location: class ScanReg
2 errors

Can somebody please tell me why?

like image 782
Lasse A Karlsen Avatar asked Oct 23 '11 01:10

Lasse A Karlsen


People also ask

How do I fix error Cannot find symbol?

In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.

What does it mean Cannot resolve symbol in Java?

In JavaLanguage, if you get 'cannot resolve symbol', you have used a name that the compiler hasn't recognized. If it is a class name, the compiler cannot find the class. This means that the class has not been imported properly, the name is misspelt (including incorrect cAsE) or the class simply does not exist.

What does error Cannot find symbol mean?

Any error that starts "cannot find symbol" means that the compiler doesn't know what that symbol (which can be a variable or a class name) refers to. In the second line of the error, where it says "symbol: class Scanner", that indicates that it doesn't know what the Scanner class is.


1 Answers

You're possibly compiling using Java 1.4 and using generics ( only available from 1.5 onwards ).

like image 109
Kal Avatar answered Oct 04 '22 21:10

Kal