How to fix error: "class, interface, or enum expected" when defining a Map outside of a class? : <p>For my own <code>Logger</code> class I want to define a map to map the priority number back to a meaningful string like follows: </p>

<pre><code>static Map&lt;int, String&gt; map = new HashMap&lt;int, String&gt;();
map.put(2, "VERBOSE");
map.put(3, "DEBUG");
map.put(4, "INFO");
map.put(5, "WARN");
map.put(6, "ERROR");
</code></pre>

<p>I wonder if there might be a function that does this automatically? But I do now know every function there is. </p>

<p>However, I define the lines just before my class definition, and then I get the error: </p>

<pre><code>Error:(14, 8) error: class, interface, or enum expected
</code></pre>

<p>and not sure what it means (maybe I cannot declare variables outside a class?). I also tried to define the map inside the class, but then the <code>put</code> method cannot be resolved. I also notice, that I have not imported a <code>Map</code> module, and AndroidStudio does not seem to require a <code>Map</code> module (i.e. the name 'Map' is not red and underlined). </p>

<p>I am very confused (as usual); I just want to get a String "ERROR" if the priority-value is 6 and so on. </p>

<p>What am I doing wrong in my case...?</p>
