Results 1 to 7 of 7

Thread: wierd error!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    wierd error!

    Hi there.

    I am trying to copy a value into a string array.

    However, it is not liking it - throwing me an "object reference is null" exception...

    now, the wierd thing is, almost the same line(s) of code work in another class in this project, but when i try to do it in a different class, this error occurs!

    the source from where i am trying to copy the value from, does have something in it. this is what im doing:

    Code:
    Dim theStringArray() as string
    
    for x = 0 to someOtherArrayList.count - 1
       theStringArray(x) = someOtherArrayList(x).ToString() 'i have tried without the ToString()
    next
    ?? whats the prob?

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: wierd error!

    It looks to me like the actual object in the someOtherArrayList(x) doesn't have anything in it. The object has been created but not instantiated.

    Where are you getting the data from? Is it definitely populating that array correctly?
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: wierd error!

    but it does! I have debugged it, and objects exist

  4. #4
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: wierd error!

    not sure about it, base on your code given, but try.
    VB Code:
    1. Dim theStringArray() as string
    2.  
    3. for x = 0 to someOtherArrayList.count - 1
    4.    ReDim Preserve theStringArray(x)
    5.    theStringArray(x) = someOtherArrayList(x).ToString() 'i have tried without the ToString()
    6. next

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: wierd error!

    You have not initialized the array. It is just a null reference. The object does NOT exist yet .

    Use:

    VB Code:
    1. Dim theStringArray() as string = New String(NUM) {}
    Where NUM is the upper bound of the array (if you want 10 elements then NUM = 9)
    I don't live here any more.

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: wierd error!

    Do NOT use this...

    Quote Originally Posted by fret
    not sure about it, base on your code given, but try.
    VB Code:
    1. Dim theStringArray() as string
    2.  
    3. for x = 0 to someOtherArrayList.count - 1
    4.    ReDim Preserve theStringArray(x)
    5.    theStringArray(x) = someOtherArrayList(x).ToString() 'i have tried without the ToString()
    6. next
    Redimming everytime will ruin performance and it is totally unneccesary.
    I don't live here any more.

  7. #7
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: wierd error!

    However you never said which object reference was causing the error.
    (Hover your mouse over the code when the app is paused and it will say "BlahBlah = Nothing" if the reference is null.

    It could be the other arraylist thats not been properly filled.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width