Re: Array Design



Hi,


Do as Jon said, post some code of where you are getting the exception. as
well as the exception Message and/or StackTrace to give a better idea of
where you have the problem

ITOH it's pretty sure you are referencing an element in the array that you
have not initializated.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"Adam Suszeck" <ASuszeck454@xxxxxxx> wrote in message
news:u0fvzqwTFHA.3188@xxxxxxxxxxxxxxxxxxxxxxx
> Thanks Jon.
>
> I'll try and explain things a bit better.
>
> The application is fairly complex and uses quite a lot of forms, so I'll
> simplify things to focus on the issue i'm having.
>
> When the application starts I initialise a state class, which contains
> details about the user and other information. It also contains an array
> of members
>
> State Class:
> public Member[] members;
>
> Form1 Class:
> I ask the user how many members to create. Ie. 10 or 20.
> in the case of 10 i initialise the array
>
> this.state.members = new Member[10];
>
> Form2 Class:
> This class basically allows the user to view the members that are
> currently in the application.
> If the array is null, then there are no members and hence no members can
> be displayed.
>
> if the members array has been initialised and populated then the members
> will be displayed.
>
> The reason i store members in state, is because I need to use the array in
> other forms, and it's an easier way of making the data available to other
> forms that may require it.
>
> I hope this explains what I'm trying to do.
>
> Regards,
> Adam
>
> "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
> news:MPG.1ce019d1839b9dba98c07d@xxxxxxxxxxxxxxxxxxxxxxx
>> Adam Suszeck <ASuszeck454@xxxxxxx> wrote:
>>> I have an application that has a state class, which basically stores
>>> application information for other forms to access during the execution
>>> of
>>> the application.
>>>
>>> In state, I store an array which contains a number of positions.
>>> Depending
>>> on what the user is doing in the application, this may hold 10 or 20
>>> items.
>>>
>>> The array length and items are set by another form in the application,
>>> ie.
>>> not the state class.
>>>
>>> The trouble is, I'm running into problems with null reference pointers.
>>> So
>>> despite checking first off that the array is set and is not empty, i
>>> still
>>> have exceptions cropping up.
>>>
>>> Should I just wrap this in a try catch block and handle any exceptions,
>>> or
>>> is there a better way of doing this?
>>
>> Using a try/catch block is almost certainly the wrong way of going. You
>> need to understand exactly why you're getting the exceptions first -
>> and unfortunately, it's hard to help on that front without seeing some
>> code.
>>
>> 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 - <skeet@xxxxxxxxx>
>> http://www.pobox.com/~skeet
>> If replying to the group, please do not mail me too
>
>


.



Relevant Pages

  • Re: Array Design
    ... When the application starts I initialise a state class, ... public Membermembers; ... in the case of 10 i initialise the array ... >> have exceptions cropping up. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Array Design
    ... > When the application starts I initialise a state class, ... > I ask the user how many members to create. ... > in the case of 10 i initialise the array ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Jon Skeets thread pooling sample
    ... >> event handlers the rest of the time, I think I'll go for something like ... That means I don't have to swallow *any* exceptions, ... the parameter array should be cloned at construction time or not.) ...
    (microsoft.public.dotnet.general)
  • Re: visibility matter on converting object to array
    ... i'll get an array having keys that from member variable's name ... i guessed "i can get public members but not protected, private, static ... Is it right way to access object members?(by converting to ...
    (comp.lang.php)
  • Re: extract items from list in single field
    ... Try using the Splitfunction to change the delimited string into an array. ... You would then loop through the members of the array and write one record to ...
    (microsoft.public.access.modulesdaovba)

Quantcast