473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Null reference exception

I have declared an array and when i use it in vb.net, I get a warning
that
variable arrClash has been used before it has been assignes a value. A
null reference exception could result at run time. This is my piece of
code;

Dim arrClash() As String

Dim i As Integer
Dim k As Integer
i = 0

For k = 1 To 4 Step 1
Dim drpDown As New DropDownList
drpDown = Page.FindControl("dropBasis" + k.ToString)
If drpDown.SelectedValue <"" Then
arrClash(i) = drpDown.SelectedValue
i += 1
End If
Next

Please tell me how do I set object rerference to null??????

Feb 15 '07 #1
1 2717
On Feb 15, 6:10 am, "Garg" <shivaniga...@gmail.comwrote:
I have declared an array and when i use it in vb.net, I get a warning
that
variable arrClash has been used before it has been assignes a value. A
null reference exception could result at run time. This is my piece of
code;

Dim arrClash() As String

Dim i As Integer
Dim k As Integer
i = 0

For k = 1 To 4 Step 1
Dim drpDown As New DropDownList
drpDown = Page.FindControl("dropBasis" + k.ToString)
If drpDown.SelectedValue <"" Then
arrClash(i) = drpDown.SelectedValue
i += 1
End If
Next

Please tell me how do I set object rerference to null??????


What you don't understand is that DECLARING and INSTANTIATING is two
different things in the .Net world...
You probably come from a dynamic language like JavaScript or something
where this isn't all that important...

What you have done in the above is to say that "I've got this variable
which I'll use somewhere" but you still haven't
actually CREATED that variable abd hence the warning...!!

To make a long story short use:
Dim x as New List(Of String)

....instead of your string array, and read a book on the .Net
framework...!!
And while you're at it, ditch VB.NET and learn a "real" programming
language... (hint; C#... ;)

..t

--
http://ajaxwidgets.com
Free ASP.NET Ajax Widgets NOW!

Feb 15 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
5
by: Boniek | last post by:
Hi I define a public property in a new form and I can see this property in table of Properties in Visual. How I can hide this property to see only in code ? Thank's Boniek
0
by: Matt | last post by:
Hi all, I'm having a very strange problem. The third line in the following code gives me a null reference exception when used in an ASP.Net web page. The code is called on the click of a...
2
by: I am Sam | last post by:
I keep getting the following exception error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request....
0
by: webbsk | last post by:
I keep getting an exception when I call the DataAdapter Update method. I have been trying to figure out what is causing the null reference exception for this code for what seems like forever: ...
18
by: Denis Petronenko | last post by:
Hello, in the following code i have segmentaion fault instead of exception. Why? What i must to do to catch exceptions in such situation? Used compiler: gcc version 3.3.6 (Debian 1:3.3.6-13) ...
3
by: Ganesh Palaniappan | last post by:
We're getting following exception for the below piece of code. We're wondering how it is possible since we're having a null check for objGraphics and strokePen... Exception:...
2
by: Weeble | last post by:
Back in C++, I had a type that looked something like this (entering from memory so this might not quite compile): template <class T> class NotNull { private: T* value; public: NotNull(T*...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
76
by: valentin tihomirov | last post by:
As explained in "Using pointers vs. references" http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca , the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.