473,387 Members | 1,516 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,387 software developers and data experts.

Adding an ArrayList to an ArrayList?

It doesn't seem to work. I get the error:

System.NullReferenceException
Object reference not set to an instance of an object.

Here's the code:

public ArrayList _rar;
....
private void DoRAR(ArrayList array)
{
...
_rar.Add(array);
...
}

I tried ArrayList.AddRange() too, and I tried declaring _rar as a string
array. How am I supposed to add an array to an array?

Thanks,

Gustaf

Nov 15 '05 #1
4 1800
I'm not sure what you are trying to do. An arraylist takes object, so
basically anything can be put into an arraylist.

Did you intialize the arraylist?
Somewhere along the line, before calling Add you have to initialize
'array' with new ArrayList to create the list. Otherwise it's just a null
object, and get object reference not set to an instance of an object,
which basically means, array isn't pointing to an arraylist.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
construct the ArrayList first

_rar = new ArrayList();
"Gustaf Liljegren" <gu**************@bredband.net> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
It doesn't seem to work. I get the error:

System.NullReferenceException
Object reference not set to an instance of an object.

Here's the code:

public ArrayList _rar;
...
private void DoRAR(ArrayList array)
{
...
_rar.Add(array);
...
}

I tried ArrayList.AddRange() too, and I tried declaring _rar as a string
array. How am I supposed to add an array to an array?

Thanks,

Gustaf

Nov 15 '05 #3
Ah, upon rereading you code you may have failed to initialize _rar.
In your class constructor, write

_rar = new ArrayList();

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
"Morten Wennevik" <Mo************@hotmail.com> wrote:
In your class constructor, write
_rar = new ArrayList();


Yes, that's it. Thanks both of you.

Gustaf
Nov 15 '05 #5

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

Similar topics

2
by: Anchor | last post by:
Hi All, I was hoping someone could help me out. I am new to VB.NET and I don't know the language too well. I am trying to add an object instance of a class to an array like in the code snipet...
2
by: Vishal Somaiya | last post by:
Hello I am trying read from a xml file, pull the values in a object and then add the object to an ArrayList. I am using a 'while' loop to move through each node in the xml file and pulling the...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: NuB | last post by:
I need some help on this, I'm trying to add to an arrayList and its not working here is what i have public ArrayList carMake public ArrayList _CarMake { get { carMake; } set( carMake = value;...
1
by: San | last post by:
Hi, I'm using a Managed C++ project with MFC support. I have an ArrayList pointer object alValue (ArrayList* alValue) to this object i want to add all the elements present in Vector<double>...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
2
by: Tomek R. | last post by:
Hello ! I've got weird problem when adding new datagrid item. Here is the situation: my grid dgDeps is binded to DepartmentList arraylist, stored in Session between round-trips.. To add new...
47
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R...
5
by: Extremest | last post by:
Is there a way to add new items to an arraylist witht he indexer? like with a normal array I can just do like array = new. What I have read with arraylist it will throw an exception if I try to...
2
by: canoewhiteh2o | last post by:
I am having trouble adding data columns to a disconnected database. I first load a datatable using: private DataTable dtMacros = new DataTable(); private ArrayList macro = new ArrayList();...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.