✅ Library is a null value
Hello, I am currently making a library application using Winforms. However, I am currently facing the issue of getting a null value for my library whenever I try to add a book. Can someone tell me what the issue with my code is?
Github: https://github.com/Allen620-arc/LibraryManagementSystem
GitHub
GitHub - Allen620-arc/LibraryManagementSystem
Contribute to Allen620-arc/LibraryManagementSystem development by creating an account on GitHub.
16 Replies
That's a lot of files and a lot of lines of code
Where does the error happen?
Well there are a lot of places where that error happens
For example:
When pressing Add Books button, filling out the form and pressing save, I get an error at line 26 saying:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
library was null.
This is in the AddBooks.cs file btw
There's no such file in the repo
Did you mean
AddBookForm.cs
?Yeah sorry
Well, that would mean that either the constructor is not called, or the constructor itself gets a
null
passed to it
It seems to be called from LibraryForm
And I don't see the library
field being initialized anywhere in there
So, that's your nullYou mean in the LibraryForm?
I initialized it in line 15 there
No, you did not
You created a field
library
of type Library
and left it uninitializedAngius
REPL Result: Failure
Console Output
Exception: NullReferenceException
Compile: 536.248ms | Execution: 44.995ms | React with ❌ to remove this embed.
You said "this is a box for apples" and did not put any apples in it
Ok yeah I fixed the error
Thanks
I didn't know how I missed that
How do I close post again?
$close
If you have no further questions, please use /close to mark the forum thread as answered
$close
If you have no further questions, please use /close to mark the forum thread as answered