Adding an ArrayList to an ArrayList?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gustaf Liljegren

    #1

    Adding an ArrayList to an ArrayList?

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

    System.NullRefe renceException
    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.AddRa nge() too, and I tried declaring _rar as a string
    array. How am I supposed to add an array to an array?

    Thanks,

    Gustaf

  • Morten Wennevik

    #2
    Re: Adding an ArrayList to an ArrayList?

    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/

    Comment

    • news.microsoft.com

      #3
      Re: Adding an ArrayList to an ArrayList?

      construct the ArrayList first

      _rar = new ArrayList();


      "Gustaf Liljegren" <gustaf.liljegr en@bredband.net > wrote in message
      news:e0jCXjsoDH A.2444@TK2MSFTN GP09.phx.gbl...[color=blue]
      > It doesn't seem to work. I get the error:
      >
      > System.NullRefe renceException
      > 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.AddRa nge() too, and I tried declaring _rar as a string
      > array. How am I supposed to add an array to an array?
      >
      > Thanks,
      >
      > Gustaf
      >[/color]


      Comment

      • Morten Wennevik

        #4
        Re: Adding an ArrayList to an ArrayList?

        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/

        Comment

        • Gustaf Liljegren

          #5
          Re: Adding an ArrayList to an ArrayList?

          "Morten Wennevik" <MortenWennevik @hotmail.com> wrote:
          [color=blue]
          >In your class constructor, write
          >_rar = new ArrayList();[/color]

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

          Gustaf

          Comment

          Working...