motor75

Hello All:

I'm having a problem sending an ArrayList as a parameter to a method in a different class. Here is my sending call (fileLines is already defined as an ArrayList of ArrayLists):

ArrayList line = ( ArrayList ) fileLines [ ++i ];

returnString = globalDefs.LoadGlobals( line );

The method is defined as follows:

public String LoadGlobals ( ArrayList line )

{

if ( line.Count != 24 )

{

return "There was not 24 tokens in the panel global definition section.";

}

return "Passed";

}

However, when I invoke the code, I get a nullReferenceException for "line" in the call to LoadGlobals. I can see that "line" is populated with text data for the ArrayList - but C# still thinks it is a Null reference. As a C++ programmer, this is a simple fix with the use of pointers - but in C#, I can't seem to remedy the situation.

Any help would be greatly appreciated - thanks!




Re: Visual C# General ArrayList as a Parameter

Peter Ritchie

If fileLines[++i] returned null you should be getting an exception, which means line can't be null at the call to LoadGlobals.

Are you should you're including everything that reproduces this problem






Re: Visual C# General ArrayList as a Parameter

Matthew Watson

Maybe it's globalDefs that is null





Re: Visual C# General ArrayList as a Parameter

Peter Ritchie

Matthew Watson wrote:
Maybe it's globalDefs that is null

That sounds far more likely. Silly, me, I assumed the OP actually viewed line in the debugger and saw that it was null.




Re: Visual C# General ArrayList as a Parameter

motor75

Actually, globalDefs was null - something I never thought to check for. Thanks for the help!