[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

ArrayList NullReferenceException (should be easy to solve)

(vavavoomy2)

12/26/2002 12:57:00 AM

Hi, I am puzzled over a NullReferencEexception in my code, so I wonder
if I am incorrectly using the ArrayList or Hashtable class. I don't
see what could be causing it. Does anyone have a idea?

Here is code:

1 if (vSets[s] == null)
2 vSets[s] = new ArrayList();
3 ((ArrayList) vSets[s]).Add(key); // this line causes the
exception.


and here is the declarations:
Hashtable vSets = new Hashtable();
Object key = new Object();

Basically from the Microsoft debugger, I know that vSets exists, and
that lines 1 and 2 are executed. So vSets[s] actually has a new
arrayList created, I can se it in the debugger. Also, I can see in
teh debugger that "key" is also an existing object.

What else is left?
1 Answer

Bryce Marshall

9/28/2002 11:02:00 PM

0

What about the value of s? You cannot use a null value as a key in a
Hashtable (the Hashtable will try to call the GetHashcode method on it).

Regards,

Bryce Marshall

"vavavoomy2" <vavavoomy2@yahoo.com> wrote in message
news:c5e42899.0209271210.1536fcea@posting.google.com...
> Hi, I am puzzled over a NullReferencEexception in my code, so I wonder
> if I am incorrectly using the ArrayList or Hashtable class. I don't
> see what could be causing it. Does anyone have a idea?
>
> Here is code:
>
> 1 if (vSets[s] == null)
> 2 vSets[s] = new ArrayList();
> 3 ((ArrayList) vSets[s]).Add(key); // this line causes the
> exception.
>
>
> and here is the declarations:
> Hashtable vSets = new Hashtable();
> Object key = new Object();
>
> Basically from the Microsoft debugger, I know that vSets exists, and
> that lines 1 and 2 are executed. So vSets[s] actually has a new
> arrayList created, I can se it in the debugger. Also, I can see in
> teh debugger that "key" is also an existing object.
>
> What else is left?