C
C#•16mo ago
TheStellarOne

Null Reference error but it's not null?

System.NullReferenceException: 'Object reference not set to an instance of an object.' Typically yeah this is an easy error to solve, but I already have defined this? Variable j is already defined as an int with a value of 0: int j = 0;, so why is this error being thrown?
No description
No description
35 Replies
Thinker
Thinker•16mo ago
Ints cannot be null so it's likely something different which is the issue Are you debugging in release mode by any chance?
TheStellarOne
TheStellarOneOP•16mo ago
No, still in debug
TheRanger
TheRanger•16mo ago
is Optimize code set to true in ur project settings?
TheStellarOne
TheStellarOneOP•16mo ago
is it set to true by default? If not, then no
TheRanger
TheRanger•16mo ago
check ur project settings in case
TheStellarOne
TheStellarOneOP•16mo ago
No it is not checked
Honza K.
Honza K.•16mo ago
show us the call stack pls
TheRanger
TheRanger•16mo ago
ur probably running multiple threads
TheStellarOne
TheStellarOneOP•16mo ago
Correct So all this code is in the function RefreshJournals
TheStellarOne
TheStellarOneOP•16mo ago
No description
TheRanger
TheRanger•16mo ago
i assume the exception was thrown in a different thread but VS incorrectly shows it was thrown in this thread instead
TheStellarOne
TheStellarOneOP•16mo ago
I'm going to launch the exe from cmd so I can see the crash output Okay for some reason it launches then immediately exits, but the form stays up for a few seconds after
TheStellarOne
TheStellarOneOP•16mo ago
No description
TheStellarOne
TheStellarOneOP•16mo ago
No description
TheStellarOne
TheStellarOneOP•16mo ago
Let me enable console for forms
Honza K.
Honza K.•16mo ago
can you send the call stack from the exception?
TheStellarOne
TheStellarOneOP•16mo ago
Yes hold on
TheStellarOne
TheStellarOneOP•16mo ago
First here is the console output
No description
TheStellarOne
TheStellarOneOP•16mo ago
Where is the call stack again?
TheRanger
TheRanger•16mo ago
in visual studio
TheStellarOne
TheStellarOneOP•16mo ago
yes I know But like Ctrl Alt C doesn't work
TheRanger
TheRanger•16mo ago
you should see a window like this on the bottom right of your VS
No description
TheStellarOne
TheStellarOneOP•16mo ago
No description
TheRanger
TheRanger•16mo ago
ur program needs to be running and breakpointed somewhere first you should see it when your VS shows the exception
TheStellarOne
TheStellarOneOP•16mo ago
No description
TheRanger
TheRanger•16mo ago
i assume j++ is at line 178?
TheStellarOne
TheStellarOneOP•16mo ago
correct Ironic im better at threading in assembly and C without libraries than C# with libraries 😭
TheRanger
TheRanger•16mo ago
is JournalsDrive not null? are you changing the value of j somewhere else other than from this line?
TheStellarOne
TheStellarOneOP•16mo ago
im such an idiot JournalsDrive was null because i commented out the wrong one 😭
TheStellarOne
TheStellarOneOP•16mo ago
No description
TheStellarOne
TheStellarOneOP•16mo ago
Thank yall so much But it might not be over because I don't think it successfully read the ntfs journals
TheRanger
TheRanger•16mo ago
you were probably running an older version of ur program thus why VS pointed at the wrong line
TheStellarOne
TheStellarOneOP•16mo ago
I mean I did clean and recompile I solved an error and gained 3 more im going to bed thanks yall <3
Bailey
Bailey•16mo ago
Maybe I'm wrong but I noticed you create are overwriting the created thread everytime in foreach(tab ......) Tread thread = new ...... ==> every tab the reference is distroyed by the new thread. You probably need a list or an array of threads
TheStellarOne
TheStellarOneOP•16mo ago
it works just fine but thanks anyways :3

Did you find this page helpful?