Java: Cannot find symbol error on Map, HashMap

29.5k views Asked by At

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?

2

There are 2 answers

1
Kal On

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

3
Edward Aung On

You need to declare your inner class as static

public static class ScanReg {}

Else, put in different java file and import ScanReg.