 |
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

May 20th, 2005, 10:59 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Object reference not set to an instance of an obj.
Hey,
Can anybody please help me solve this little problem, I've been working on it for the past 3 days, I've googled and re-written the code, I'm getting the following error;
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error: LINE 269
Line 267:
Line 268: Sub Button1_Click(sender As Object, e As EventArgs)
Line 269: ServerSpec( _
Line 270: (DropDownList1.SelectedItem.Value), _
Line 271: (servercolour.SelectedItem.Value), _
I'll post code if required.
As always any suggestions and help greatly appreciated
D
|

May 20th, 2005, 12:42 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
This indicates that either one of the controls is not instantiated or that one of the controls does not have a selected item.
One thing to check is the condition under which you are loading the contents of those dropdownlists. If you are binding them on every page hit then when the button click handler fires, the list won't have a selected item, even though in the browser the DDL is sitting on the first item (because it has to, not because it is selected).
- Peter
|

May 22nd, 2005, 04:18 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Peter,
So what I have to do is to make sure that all my DDL's have a selected statement inserted.
D
|

May 22nd, 2005, 07:46 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Yes, the DDL will have to have a selected item but you don't have to explicitly select an item in the code-behind.
In normal behavior a drop down list will always have a selected item EXCEPT for the page execution where you bind the list then try to call SelectedItem on the DDL. That's why I suggested you check to see when the list is being databound. On any page hit after the first, as long as the list isn't being databound before you try to look at SelectedItem, the list will always have an item selected (even if it's the first item in the list).
- Peter
|

May 23rd, 2005, 03:32 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey Peter,
I've gone through every bit of my code I've made chages with the selected index value, and I'm still getting the same error. I don't know what else to do, I've re-written some of the code and I've re-written the database.
|

May 23rd, 2005, 07:52 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Without being able to debug the code myself, I don't know how else to help. Have you beeng able to see that values are being seen at the function call?
- Peter
|

May 23rd, 2005, 10:35 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey Peter,
Just wanted to say thanks for all your help, it turned out that I had a DDL hidden, silly me.
Sorry
D
|

May 27th, 2005, 04:18 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hummmmmm....
Seems like I haven't resolved this problem, if I wrote a Try....Catch Statement, would that help me rectify the exception?
Because when I'm writing to my database I have it so that Nulls are accepted, but when I click the save button I keep getting that error only when some fields are left blank.
So any idea how to write such a statement?? I've googled away, but I want it to happen on button click etc.
D
|

June 1st, 2005, 08:28 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
A try...catch won't necessarily help solve the problem, it may just mask it. It sounds like you need to do some extensive debugging to see how blank/null values are getting into the statement.
- Peter
|
|
 |