Java: Cannot find symbol error on Map, HashMap
Asked Answered
B

2

9

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?

Broth answered 23/10, 2011 at 1:15 Comment(3)
You don't have your own local package named java.util do you? I would try to import the whole class name: import java.util.Map; and same for the other util classes used such as HashMap.Hejira
Kal may be on to something (1+ to him!).Hejira
I cannot recreate this based on the info in the question. Something else is going on. And since the OP most likely doesn't care anymore, it should be closed as "not reproducible".Padron
N
2

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

Nadenenader answered 23/10, 2011 at 1:36 Comment(1)
Sorry .. I cannot reproduce the problem. I copied your ScanReg.java and it compiled fine.Nadenenader
K
-2

You need to declare your inner class as static

public static class ScanReg {}

Else, put in different java file and import ScanReg.

Kowalski answered 23/5, 2019 at 3:18 Comment(3)
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.Padron
I recreated the problem and test this to be working solutionKowalski
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.Padron

© 2022 - 2024 — McMap. All rights reserved.