473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ArrayList in Hashtable

Hi!
What i want to do, is to put an ArrayList into a Hashtable. So i can access
the ArrayList fast over the key-indexing of the Hashtable.

What i did is to put the ArrayList into the Hashtable

hash[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias
Nov 16 '05 #1
5 12466
Matthias,

The only way that this could happen (assuming that hash is the same
hashtable in both instances) is if the key that was used to fetch the
ArrayList is different than the key that was used to get the ArrayList. Are
you sure they are the same?

Also, are you sure that nothing modified hash or the value pointed to by
key between the time that you set it and the time you try to access it?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Matthias Kwiedor" <cr********@hotmail.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
Hi!
What i want to do, is to put an ArrayList into a Hashtable. So i can access the ArrayList fast over the key-indexing of the Hashtable.

What i did is to put the ArrayList into the Hashtable

hash[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias

Nov 16 '05 #2
Matthias,

The only way that this could happen (assuming that hash is the same
hashtable in both instances) is if the key that was used to fetch the
ArrayList is different than the key that was used to get the ArrayList. Are
you sure they are the same?

Also, are you sure that nothing modified hash or the value pointed to by
key between the time that you set it and the time you try to access it?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Matthias Kwiedor" <cr********@hotmail.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
Hi!
What i want to do, is to put an ArrayList into a Hashtable. So i can access the ArrayList fast over the key-indexing of the Hashtable.

What i did is to put the ArrayList into the Hashtable

hash[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias

Nov 16 '05 #3
Matthias Kwiedor <cr********@hotmail.com> wrote:
What i want to do, is to put an ArrayList into a Hashtable. So i can access
the ArrayList fast over the key-indexing of the Hashtable.

What i did is to put the ArrayList into the Hashtable

hash[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.


Did you ever actually initialise arraylist to have a reference to an
actual instance of ArrayList, rather than just being null?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Matthias Kwiedor <cr********@hotmail.com> wrote:
What i want to do, is to put an ArrayList into a Hashtable. So i can access
the ArrayList fast over the key-indexing of the Hashtable.

What i did is to put the ArrayList into the Hashtable

hash[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.


Did you ever actually initialise arraylist to have a reference to an
actual instance of ArrayList, rather than just being null?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
This can happen if the object which is your key overides Equals() and
returns false erroneously.

Try this:

bool valid = hash.ContainsKey(key);

What is "valid" - if its false - then it's not finding a match to your key.

"Matthias Kwiedor" <cr********@hotmail.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
Hi!
What i want to do, is to put an ArrayList into a Hashtable. So i can access the ArrayList fast over the key-indexing of the Hashtable.

What i did is to put the ArrayList into the Hashtable

hash[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Matthias Kwiedor | last post by:
Hi@all! I have a app (c#) where i load up a external dll (managed code from c#) with a small arraylist and hashtable in two routines (about 40000 objects in each arraylist and hashtable). If...
6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
5
by: Netmonster | last post by:
Hello, Does any one have an example of how to create an ArrayList of objects? i.e. ArrayList of ArrayLists or an ArrayList of Hashtables? Thanks in advance KC
11
by: paradox | last post by:
Basically I have an ArrayList of strings; I need a fast way of searching through and comparing the elements of the ArrayList and the return an ArrayList of items that have 3 Duplicates. For...
3
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList...
3
by: Sam | last post by:
Hi Everyone, I have a stucture below stored in an arraylist and I want to check user's input (point x,y) to make sure there is no duplicate point x,y entered (string label can be duplicated). Is...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
2
by: Bruce | last post by:
Hi I am having a problem understanding the exact advantages of using an ArrayList over a Hashtable in any situation. In most areas of an application I am working on, lookup needs to be fast. If I...
7
by: Kamran Shafi | last post by:
Hi, I am creating an arraylist (say masterArrayList) of hashtables, where each hashtable (say table) is of the format key=string, value = arraylist of strings (say existing_strings). In a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.