HashMap
Hi there,
I am new to these forums and I am having an error with compiling my code.
This is the code:
Map words = new HashMap();
String word;
words.put(word, new Count(word, 1)); // this is the line that is not compiling
If anyone can offer me any help, that would be great.
Thanks
# 3
All local variables should be initialized before Use....
words.put(word,....);
Here word is your key and new Count is your value. In this statement you use the variable word, before intitalizing ....
Java spec, states that all local variables should be initialized before its used..
# 4
it may be because you are not creating the hashmap with the proper generic types.. for example
/* This map stores Count String pairs where the String is the
key and the Count object is the value stored. */
HashMap< String, Count > map = new HashMap< String, Count > ();
String word;
words.put(word, new Count(word, 1));
# 5
Hi there,
I fixed my problem, it was silly, I made a mistake with the contructor in the Count class.
Sorry to inconvenience anyone.
Thanks
Cheers