XandrUu
XandrUu

Reputation: 1179

ERROR when I try to instantiate a String[] object reference not set to an instance of an object

I'm trying to read some information from a text file and put in a String[] I read from the file succesfully, but when I try to put the information in the String[], I get this error :"object reference not set to an instance of an object". This is the code where I get the error:

string total = linie.Replace(idCont + "_" + rows["JOB"].ToString() + "_" + Loturi[i] + " : ", "")
Vol_Plicuri[i] = total.Split('|')[0].Trim();

I don't know how to get bypass this error. Thanks!

Upvotes: 1

Views: 76

Answers (2)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726529

I put a mbox befor the "Vol_Plicuri[i] = total.Split('|')[0].Trim();" and was not null.

Make sure that Vol_Plicuri is set to a non-null value.

Upvotes: 1

Servy
Servy

Reputation: 203821

Inspect every variable in a debugger to see which is null. If you find this difficult, breaking up complex lines into multiple simpler lines of code can make it easier. (Your stack trace will give you the line that errors, so if you do less per line there is less guessing in what failed.) If certain values may actually legitimately be null, you may need to add in 'if not null' wrappers around such statements.

Upvotes: 0

Related Questions