Results 1 to 2 of 2

Thread: public variable problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Location
    New Jersey, USA
    Posts
    119

    public variable problem

    I have declared a public arraylist: public input as arraylist = new arraylist()
    at the general declaration seciton of my app.

    When a button click event occurs, it gets a list of images from a folder, then for each image places an entry in a two dimensional array of arraylists, 2 arraylists for each image. the entry contains the arraylist filled by a subroutine, and the second one with another arraylist filled by another subroutine.

    Then, i have a loop where it goes through the two dimensional array of arraylists, assigining the value of the first item of the second dimension of the array: input = trainingdata(a, 0). these are both system.arraylist type. then, it calls a subroutine.
    Here is the important part.
    the subroutine procedes to unload the items in input arraylist into an array. now for some reason, VB.NET throws an exception "Object reference not set to an instance of an object", with the value of input.item(a) being "nothing".
    this makes no sense, for the arraylist is a public arraylist, declared specifically "... = New arraylist()" which instantiates object. being public, nothing should happen to it between subs. what is wrong here?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: public variable problem

    Might help to see some code, there are a few possibilities that may be happening. However, if you put a breakpoint on the end of that first loop (or sub) that assigns a value to input, you can confirm that input.item(a) is not nothing (Shift+F9). Then you can step through to the line with the error. However, I suspect that you will find your problem before you reach that line.

    As a guess, I expect that you are in some way expecting input to hold a copy of trainingdata(a,0), when in fact trainingdata(a,0) is holding a pointer to an object, and input is holding a copy of that pointer. Thus if anything deletes whatever trainingdata(a,0) is pointing to, then input remains holding a pointer to nothing. Just a guess, though.
    My usual boring signature: Nothing

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