7

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?

Lasse A Karlsen
  • 801
  • 5
  • 14
  • 23

2 Answers2

2

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

Kal
  • 24,724
  • 7
  • 65
  • 65
  • 1
    Sorry .. I cannot reproduce the problem. I copied your ScanReg.java and it compiled fine. – Kal Oct 23 '11 at 01:39
-2

You need to declare your inner class as static

public static class ScanReg {}

Else, put in different java file and import ScanReg.

Edward Aung
  • 3,014
  • 1
  • 12
  • 15
  • This won't solve the problem he was trying to solve. It was about library classes and imports. Also, note that this is an **ancient** question. If the OP hasn't solved the problem by now, he will no longer care. – Stephen C May 23 '19 at 03:23
  • I recreated the problem and test this to be working solution – Edward Aung Aug 27 '21 at 07:35
  • Well I >could not< recreate the problem. When I compile those two files from the command line (Java 8). I don't get any compilation errors. There was something "funky" that the OP was not telling us. – Stephen C Aug 27 '21 at 08:11