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
Thinker11mo ago
Ints cannot be null so it's likely something different which is the issue Are you debugging in release mode by any chance?
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
No, still in debug
TheRanger
TheRanger11mo ago
is Optimize code set to true in ur project settings?
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
is it set to true by default? If not, then no
TheRanger
TheRanger11mo ago
check ur project settings in case
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
No it is not checked
Honza K.
Honza K.11mo ago
show us the call stack pls
TheRanger
TheRanger11mo ago
ur probably running multiple threads
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
Correct So all this code is in the function RefreshJournals
TheRanger
TheRanger11mo ago
i assume the exception was thrown in a different thread but VS incorrectly shows it was thrown in this thread instead
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
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
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
Let me enable console for forms
Honza K.
Honza K.11mo ago
can you send the call stack from the exception?
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
First here is the console output
No description
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
Where is the call stack again?
TheRanger
TheRanger11mo ago
in visual studio
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
yes I know But like Ctrl Alt C doesn't work
TheRanger
TheRanger11mo ago
you should see a window like this on the bottom right of your VS
No description
TheRanger
TheRanger11mo ago
ur program needs to be running and breakpointed somewhere first you should see it when your VS shows the exception
TheRanger
TheRanger11mo ago
i assume j++ is at line 178?
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
correct Ironic im better at threading in assembly and C without libraries than C# with libraries 😭
TheRanger
TheRanger11mo ago
is JournalsDrive not null? are you changing the value of j somewhere else other than from this line?
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
im such an idiot JournalsDrive was null because i commented out the wrong one 😭
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
Thank yall so much But it might not be over because I don't think it successfully read the ntfs journals
TheRanger
TheRanger11mo ago
you were probably running an older version of ur program thus why VS pointed at the wrong line
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
I mean I did clean and recompile I solved an error and gained 3 more im going to bed thanks yall <3
Bailey
Bailey11mo 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
~✰ 𝒮𝓉𝑒𝓁𝓁𝒶𝓇 ✰~
it works just fine but thanks anyways :3
Want results from more Discord servers?
Add your server