Why are you making it static?
Just do this:
public class MyClass
{
private Map<Integer, String> myHashMap;
public MyClass()
{
myHashMap = new HashMap<Integer, String>();
myHashMap.put(1, "one");
myHashMap.put(2, "two");
}
}
Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware
On Tue, Apr 3, 2012 at 2:48 PM, Graham Bright <[email protected]>wrote:
>
>
>
> private static final Map<Integer, String> myHashMap = new HashMap<Integer,
> String>();
> static {
> myHashMap.put(1, "one");
> myHashMap.put(2, "two");
> }
>
> Sorry I found the problem
>
> thanks
>
> graham
>
>
> On Tue, Apr 3, 2012 at 10:42 PM, Justin Anderson <[email protected]>wrote:
>
>> Can you provide some actual snippets of code... like more than just how
>> you are declaring your HashMap?
>>
>>
>> Thanks,
>> Justin Anderson
>> MagouyaWare Developer
>> http://sites.google.com/site/magouyaware
>>
>>
>> On Tue, Apr 3, 2012 at 2:42 PM, Justin Anderson <[email protected]>wrote:
>>
>>> One more question when I declare a test HashMap it seems only to work as
>>>> static private static final Map<Integer, String> myHashMap = new
>>>> HashMap<Integer, String>(); static { myHashMap.put(1, "one");
>>>> myHashMap.put(2, "two"); } and I am unable to access the HashMap outside of
>>>> the brackets. So new ArrayList<String>(MyHashMap.KeySet()) fails as
>>>> MyHashMap cannot be resolved ... ?
>>>>
>>> What?
>>>
>>>
>>> Thanks,
>>> Justin Anderson
>>> MagouyaWare Developer
>>> http://sites.google.com/site/magouyaware
>>>
>>>
>>> On Tue, Apr 3, 2012 at 2:37 PM, Graham Bright
>>> <[email protected]>wrote:
>>>
>>>> One more question when I declare a test HashMap it seems only to work
>>>> as static private static final Map<Integer, String> myHashMap = new
>>>> HashMap<Integer, String>(); static { myHashMap.put(1, "one");
>>>> myHashMap.put(2, "two"); } and I am unable to access the HashMap outside of
>>>> the brackets. So new ArrayList<String>(MyHashMap.KeySet()) fails as
>>>> MyHashMap cannot be resolved ... ?
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to
>>>> [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/android-developers?hl=en
>>>>
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en