473,396 Members | 1,995 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.

An unhandled exception of type 'System.NullReferenceException'

Hi Everybody,

I've been working with webservices. But I keep stumbling on the same error.

An unhandled exception of type 'System.NullReferenceException'
Additional information: Object reference not set to an instance of an object.

This is my piece of code

Expand|Select|Wrap|Line Numbers
  1.   getKeyTags _keyTags = new getKeyTags();
  2.             _keyTags.login = login;
  3.             KeyTagBean[] keyTags = null;
  4.             lock (wService)
  5.             {
  6.                 keyTags = wService.getKeyTags(_keyTags);
  7.             }
  8.             Hashtable keyTagHash = new Hashtable();
  9.             foreach (KeyTagBean bean in keyTags)
  10.             {
  11.                keyTagHash.Add(bean.keyTagID, bean);
  12.             }  
  13.             dataGridView1.DataSource = keyTagHash;     
When I get the error, the keyTagHash.Add line highlights.


Can anyone help me please?

THanks
May 11 '10 #1
5 2126
Dheeraj Joshi
1,123 Expert 1GB
is bean.keyTagID is unique?

Regards
Dheeraj Joshi
May 11 '10 #2
yes it is.
May 11 '10 #3
ThatThatGuy
449 Expert 256MB
@willemr
keyTags = wService.getKeyTags(_keyTags);
is resulting a null value to keyTags... check it out first on debug
May 11 '10 #4
tlhintoq
3,525 Expert 2GB
Original Poster: "How do I fix a 'object reference not set to an instance of an object' error?
The line your code stopped on while debugging holds all your answers.
One of the variables/objects was created but not initialized. For example:
Expand|Select|Wrap|Line Numbers
  1. string TempString;// Created but not initialized so this is still null
  2. //versus
  3. string TempString = string.empty;
Debug your project again. This time, when it breaks on a line look at the Locals pallet to see which variable/object is null. You can also hover your mouse over each variable and the hothelp will shows its value. One of them will be null.
May 11 '10 #5
Thanks Guys, I managed to fix it.
May 11 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in...
0
by: Rafiq Ganaie via .NET 247 | last post by:
HI, I am working on a search application in C#.It is a multithreaded application.it simply takes a URL,Downloads the page using WebRequest and WebResponse classes.Unfortunately it is throwing...
1
by: Lee Holsenbeck | last post by:
Hi, I get this error in a vb.net windows application in the .exe: "An unhandled exception of type 'System.argumentException' occurred in system.drawing.dll" This occurs only on 1 user's pc,...
1
by: Merlynx | last post by:
i am getting that error with the Event() method. Don't know whether if i have used the CreateEvent function well as it is the 1st time i used it moreover i am net to C#. If anyone can point me out...
3
by: cristiank | last post by:
hi everybody, I need to clear something out, does anybody have ever encountered such an exception until now : "Un unhandled exception of type System.NullReferenceException occurred in...
1
by: brckcc | last post by:
I have a C# application that periodically gets the above exception when attempting to call ShowDialog on a particular dialog. I have created a new project, copied the dialog files (.cs and .resx)...
3
by: juli | last post by:
Hello! I keep getting this error: An unhandled exception of type 'System.NullReferenceException' occurred Additional information: Object reference not set to an instance of an object. I am...
3
by: GS | last post by:
why am i getting A first chance exception of type 'System.NullReferenceException' occurred in myapp.exe below? and what can i do get rid of it? Private Function getPrefxType() As String If...
1
by: Pedro Dinis | last post by:
i have this class library that connects to the database(see appconfig below) compiling 0 errors but when its running i amhaving this error An unhandled exception of type...
2
by: itsvineeth209 | last post by:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.