NullReferenceException Error

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 21
Reputation: scholar is an unknown quantity at this point 
Solved Threads: 0
scholar scholar is offline Offline
Newbie Poster

NullReferenceException Error

 
0
  #1
Jul 3rd, 2009
Hi Friends,
I am getting the following error with my code
"Object reference not set to instance of the object" .
My code goes as follows:

  1. ...
  2. ...
  3. string[] isem= new string[125];
  4. decimal[] perc = new decimal[125];
  5. student s1=new student();
  6. ...
  7. ...
  8. public void func()
  9. {
  10.  
  11. isem = new string[125];
  12. perc = new decimal[125];
  13. string[] temproll=new string[125];
  14. int j=0;
  15. sem = s1.calcallperc1(..., ..., ....);//calcperc1 returns an array
  16. j=-1;
  17. foreach (string s in isem)
  18. {
  19.  
  20. temproll[++j] = s.Split(' ')[0];
  21. perc[j] = Convert.ToDecimal(s.Split(' ')[1]);
  22.  
  23. }
  24.  
  25.  
  26. }
  27. ...

Please help!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 67
Reputation: S2009 is an unknown quantity at this point 
Solved Threads: 0
S2009 S2009 is offline Offline
Junior Poster in Training

Re: NullReferenceException Error

 
0
  #2
Jul 3rd, 2009
Originally Posted by scholar View Post
Hi Friends,
I am getting the following error with my code
"Object reference not set to instance of the object" .
My code goes as follows:

  1. ...
  2. ...
  3. string[] isem= new string[125];
  4. decimal[] perc = new decimal[125];
  5. student s1=new student();
  6. ...
  7. ...
  8. public void func()
  9. {
  10.  
  11. isem = new string[125];
  12. perc = new decimal[125];
  13. string[] temproll=new string[125];
  14. int j=0;
  15. sem = s1.calcallperc1(..., ..., ....);//calcperc1 returns an array
  16. j=-1;
  17. foreach (string s in isem)
  18. {
  19.  
  20. temproll[++j] = s.Split(' ')[0];
  21. perc[j] = Convert.ToDecimal(s.Split(' ')[1]);
  22.  
  23. }
  24.  
  25.  
  26. }
  27. ...


Please help!!
I think there is mistake in this statement

sem = s1.calcallperc1(..., ..., ....);//calcperc1 returns an array

Either it should be isem or the sem should be declared as an array variable since the function returns the an array.

Hope this would be help you!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC