Re: Array Design
- From: "Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
- Date: Mon, 2 May 2005 09:32:54 -0400
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
>
>
.
- References:
- Array Design
- From: Adam Suszeck
- Re: Array Design
- From: Jon Skeet [C# MVP]
- Re: Array Design
- From: Adam Suszeck
- Array Design
- Prev by Date: Re: #define on multiple files
- Next by Date: Re: Help! i need your kindly help !
- Previous by thread: Re: Array Design
- Next by thread: Re: Array Design
- Index(es):
Relevant Pages
|