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

NotifyIcon program - Button exception

When I add a Button to my NotifyIcon program I get the following:

An unhandled exception of type 'System.NullReferenceException' occurred in
unknown module.

Additional information: Object reference not set to an instance of an object.

I suspect this is a common novice error but I haven't any idea what I need to
do to get this to work. "Help" seems to be geared toward people who have been
coding for a couple of years!

The code I have added is:

Public Class Form1
<snip of all code down to last Sub>

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Me.Close()
End Sub
End Class

Any suggestions?
--
-Doug
Nov 20 '05 #1
8 1747
Use a try/catch around the lines that you think are causing this. I really
doubt this is the line causing the problem.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"bole2cant" <sh*****@xxxmission.com> wrote in message
news:40***********************@news.xmission.com.. .
When I add a Button to my NotifyIcon program I get the following:

An unhandled exception of type 'System.NullReferenceException' occurred in
unknown module.

Additional information: Object reference not set to an instance of an object.
I suspect this is a common novice error but I haven't any idea what I need to do to get this to work. "Help" seems to be geared toward people who have been coding for a couple of years!

The code I have added is:

Public Class Form1
<snip of all code down to last Sub>

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Me.Close()
End Sub
End Class

Any suggestions?
--
-Doug

Nov 20 '05 #2
A try catch block is the structured way to handle/trap exceptions. As far
as that sub, something's weird. me is VB.NET's equivalent of 'this' in C
langauges and all you are calling is Close on it. So everythign is
compiling fine you jsut get a NullReference if you leave this in? Hmm, also
missing a Handles.Clause. Go ahead and kill this code then add it again
using the ide's visual tools. It will shell out the event for you. Then
just add code (me.Close());.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"bole2cant" <sh*****@xxxmission.com> wrote in message
news:40***********************@news.xmission.com.. .
If I delete the Sub I don't get the exception error.
I'll have to look up what a try/catch is. Thanks for the reply.

-Doug

=================
"William Ryan eMVP" wrote in a message:
Use a try/catch around the lines that you think are causing this. I really doubt this is the line causing the problem.

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/

==============================
"bole2cant" wrote in a message:
When I add a Button to my NotifyIcon program I get the following:

An unhandled exception of type 'System.NullReferenceException' occurred in unknown module.

Additional information: Object reference not set to an instance of an

object.

I suspect this is a common novice error but I haven't any idea what I
need to
do to get this to work. "Help" seems to be geared toward people who
have been
coding for a couple of years!

The code I have added is:

Public Class Form1
<snip of all code down to last Sub>

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Me.Close()
End Sub
End Class

Any suggestions?


Nov 20 '05 #3
Can you post the full code?
I've got a feeling you might not be unloading the NotifyIcon properly before
closing the form??
Just a thought... expert please :D
________________________________
The Grim Reaper

"bole2cant" <sh*****@xxxmission.com> wrote in message
news:40***********************@news.xmission.com.. .
When I add a Button to my NotifyIcon program I get the following:

An unhandled exception of type 'System.NullReferenceException' occurred in
unknown module.

Additional information: Object reference not set to an instance of an object.
I suspect this is a common novice error but I haven't any idea what I need to do to get this to work. "Help" seems to be geared toward people who have been coding for a couple of years!

The code I have added is:

Public Class Form1
<snip of all code down to last Sub>

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Me.Close()
End Sub
End Class

Any suggestions?
--
-Doug

Nov 20 '05 #4
Grim Reaper,

Ah, you may be onto something. You are correct in your suggestion that I am not
unloading the Icon from the Notification tray. I sometimes have 3 or 4
instances of the icon, but eventually they go away. <g>

I have tried unloading niRedLight but cannot get the code right,
e.g., niRedLight.Dispose or niRedLight.Icon.Dispose, but that doesn't fix it.
(There is no Close option.)

How do I unload it?

As for posting the full code. Is that acceptable here? And it wouldn't show how
my properties are set....

I could post it on my web site or make it available as a download--the whole
project (or is the correct term Solution!)
What's your preference?

You may have noticed that I am also having a problem with displaying the
context menu. (A different thread)

Thanks for your reply.

-Doug

================================================== ==
"The Grim Reaper" wrote in a message:
Can you post the full code?
I've got a feeling you might not be unloading the NotifyIcon properly before
closing the form??
Just a thought... expert please :D
________________________________
The Grim Reaper
============================================= "bole2cant" wrote in a message:

When I add a Button to my NotifyIcon program I get the following:

An unhandled exception of type 'System.NullReferenceException' occurred in
unknown module.

Additional information: Object reference not set to an instance of an

object.

I suspect this is a common novice error but I haven't any idea what I need

to
do to get this to work. "Help" seems to be geared toward people who have
been
coding for a couple of years!

The code I have added is:

Public Class Form1
<snip of all code down to last Sub>

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Me.Close()
End Sub
End Class

Any suggestions?


Nov 20 '05 #5
I have just discovered what is giving me the exception error. It is NOT the
code, it is the fact that the button is on the form. If I delete the code and
leave the button on the form I still get the error message.

I decided to make the code available on my download web page.

http://www.xmission.com/~sherwin/download2.html

Question: Are all these (7) files necessary to enable someone else to download
and run my program? Also, I am concerned that the icons may not be contained in
the files I have made available. I guess any icon you have would work okay?

-Doug

=============================
"bole2cant" wrote in a message:
Grim Reaper,

Ah, you may be onto something. You are correct in your suggestion that I am not unloading the Icon from the Notification tray. I sometimes have 3 or 4
instances of the icon, but eventually they go away. <g>

I have tried unloading niRedLight but cannot get the code right,
e.g., niRedLight.Dispose or niRedLight.Icon.Dispose, but that doesn't fix it.
(There is no Close option.)

How do I unload it?

As for posting the full code. Is that acceptable here? And it wouldn't show how my properties are set....

I could post it on my web site or make it available as a download--the whole
project (or is the correct term Solution!)
What's your preference?

You may have noticed that I am also having a problem with displaying the
context menu. (A different thread)

Thanks for your reply.

-Doug

================================================== ==
"The Grim Reaper" wrote in a message:
Can you post the full code?
I've got a feeling you might not be unloading the NotifyIcon properly before closing the form??
Just a thought... expert please :D
________________________________
The Grim Reaper


Nov 20 '05 #6
"bole2cant" <sh*****@xxxmission.com> schrieb
I have just discovered what is giving me the exception error. It is
NOT the code, it is the fact that the button is on the form. If I
delete the code and leave the button on the form I still get the
error message.

I decided to make the code available on my download web page.

http://www.xmission.com/~sherwin/download2.html

Maybe I missed something, but...
a) I don't get an exception
b) btnClose_Click is not an event handler because "Handles..." is missing.
c) you don't need to call niRedLight.Icon.Dispose() because the NotifyIcon
is a component, and a component is disposed automatically when the Form is
closed and therefore disposed.
Question: Are all these (7) files necessary to enable someone else to
download and run my program? Also, I am concerned that the icons may
not be contained in the files I have made available. I guess any icon
you have would work okay?


If you select the icon in the designer, it is stored in form1.resx and
compiled as a resource in the executable.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7

"Armin Zingler" wrote in a message:
"bole2cant" wrote in a message:
I have just discovered what is giving me the exception error. It is
NOT the code, it is the fact that the button is on the form. If I
delete the code and leave the button on the form I still get the
exception error message.

I decided to make the code available on my download web page.

http://www.xmission.com/~sherwin/download2.html
<snip>


Maybe I missed something, but...
a) I don't get an exception
b) btnClose_Click is not an event handler because "Handles..." is missing.
c) you don't need to call niRedLight.Icon.Dispose() because the NotifyIcon
is a component, and a component is disposed automatically when the Form is
closed and therefore disposed.

===================================

Armin,

Thanks for your reply and for taking the time to run my program. From your list
above....

a) What I hear you saying that you ran my code without making any changes
and you didn't get the exception error db. How can that be explained? A
different version of VB.NET? (I am using VB.NET standard edition.) A setting I
need to change in ???? (setup options?)

Did the context menu work for you, Armin? (Right-clicking on niRedLight
icon....)

b) I am too much of a novice to understand ....

c) Understood. I will get rid of that code.

Does anyone using standard edition get the exception?

-Doug

Nov 20 '05 #8
"bole2cant" <sh*****@xxxmission.com> schrieb

"Armin Zingler" wrote in a message:
"bole2cant" wrote in a message:
I have just discovered what is giving me the exception error. It
is NOT the code, it is the fact that the button is on the form.
If I delete the code and leave the button on the form I still get
the exception error message.

I decided to make the code available on my download web page.

http://www.xmission.com/~sherwin/download2.html
<snip>
Maybe I missed something, but...
a) I don't get an exception
b) btnClose_Click is not an event handler because "Handles..." is
missing. c) you don't need to call niRedLight.Icon.Dispose()
because the NotifyIcon is a component, and a component is disposed
automatically when the Form is closed and therefore disposed.

===================================

Armin,

Thanks for your reply and for taking the time to run my program. From
your list above....

a) What I hear you saying that you ran my code without making any
changes and you didn't get the exception error db. How can that be
explained? A different version of VB.NET? (I am using VB.NET standard
edition.) A setting I need to change in ???? (setup options?)

Did the context menu work for you, Armin? (Right-clicking on
niRedLight icon....)


Umm... no, I didn't use the context menu. I've read the thread again but
didn't find that the error occurs when the context menu is opened - or where
does the error occur? No I had a look at the contextmneu, but it doesn't
have items. Is this intended?
b) I am too much of a novice to understand ....
Private Sub btnClose_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs)

You have to add "Handles" to have the procedure handle the click event of
the button:

Private Sub btnClose_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnClose.Click
c) Understood. I will get rid of that code.

Does anyone using standard edition get the exception?


I'm using VS 2003 Prof., WinXP Prof.

The most important thing is to tell us where and when the exception occurs
and what the message of the exception says.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9

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

Similar topics

5
by: Phil Galey | last post by:
VB.NET 2002 on Windows 2000 SP 3 When I start my program, the NotifyIcon appears in the tray, as it should. However, when I close the program, the NotifyIcon remains until I hover over it with...
0
by: petterl | last post by:
I have tried to find the error in the code below but I always get " An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object...
2
by: Derrick | last post by:
I've been working on an application which has a NotifyIcon (system tray icon), and a corresponding ContextMenu. I want to be able to update this menu dynamically. However, when I make changes to...
12
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I...
2
by: Randall Powell | last post by:
I am in the process of developing a Windows Service which will: (1) monitor multiple network shares; (2) marshal text file transfers into an SQL Server 2000 instance; and (3) provide messaging...
2
by: Amjad | last post by:
Hi, I'm using the NotifyIcon to process some text files in the background periodically. I want to display one icon in the task bar when the program is in stand by mode, and I want to display...
2
by: JR | last post by:
Hi, I need to change the notifyicon in a countdown. after about 3000-5000 times there is an error. Here is all the code. what is wrong please help
0
by: Mrozu | last post by:
Hi, VB.NET 2003 I'v got NotifyIcon, on minimize button click, my app is hiding to tray by following code: ni.Visible = True Me.Hide() Me.WindowState = FormWindowState.Minimized
3
by: Peter Holschbach | last post by:
Hi all, I've a application where I need to use NotifyIcon in a other way round. My normal windows application sometimes has to collect data. In this case I want to hide all formulares and just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.