473,464 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error: Object reference not set to an instance of an object

When I attempt to run the following code I get the
following error:

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

Being new to VB.Net I'm stumped. I have attempted
several versions of the attached code, all with the same
result. Help is unfortunately written in an
unintelligible language; your assistance would be greatly
appreciated.

I am attempting to add information in a class named Art
to an arraylist named ArtList with the Button1_click
event.

'** MODULE1 **
Imports System
Imports System.IO
Imports System.Collections
Imports System.Runtime.Serialization.Formatters.Soap
<[Serializable]()> Public Class Art
Public Title As String
Public Des As String
Public Room As String
Public Location As String
Public Value As Integer
Public Bequeth As String
Public Picture As String
End Class
Module Module1
Public ArtList As ArrayList
End Module

' ** FORM1 **
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
Button1.Click
Dim myArt As New Object
myArt = New Art
With myArt
.Title = tbTitle.Text
.Des = tbDesc.Text
.Location = tbLocation.Text
.Room = cbRoom.SelectedItem
.Value = tbValue.Text
.Picture = tbPicture.Text
.Bequeth = tbBequeth.Text
End With
ArtList.Add(myArt)
SaveFile()
End Sub
End Class

Nov 21 '05 #1
2 2444
Module Module1
Public ArtList As ArrayList
End Module

should read

Module Module1
Public ArtList As new ArrayList
End Module

any time you get that error, find the line that causes it and one object it
that line, the object hasn't been created, usually with new. (a function
could return an object to create it as well)

Chris
"GrandpaB" <an*******@discussions.microsoft.com> wrote in message
news:15****************************@phx.gbl...
When I attempt to run the following code I get the
following error:

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

Being new to VB.Net I'm stumped. I have attempted
several versions of the attached code, all with the same
result. Help is unfortunately written in an
unintelligible language; your assistance would be greatly
appreciated.

I am attempting to add information in a class named Art
to an arraylist named ArtList with the Button1_click
event.

'** MODULE1 **
Imports System
Imports System.IO
Imports System.Collections
Imports System.Runtime.Serialization.Formatters.Soap
<[Serializable]()> Public Class Art
Public Title As String
Public Des As String
Public Room As String
Public Location As String
Public Value As Integer
Public Bequeth As String
Public Picture As String
End Class
Module Module1
Public ArtList As ArrayList
End Module

' ** FORM1 **
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
Button1.Click
Dim myArt As New Object
myArt = New Art
With myArt
.Title = tbTitle.Text
.Des = tbDesc.Text
.Location = tbLocation.Text
.Room = cbRoom.SelectedItem
.Value = tbValue.Text
.Picture = tbPicture.Text
.Bequeth = tbBequeth.Text
End With
ArtList.Add(myArt)
SaveFile()
End Sub
End Class

Nov 21 '05 #2
Chris,

Thanks not only for the solution to my error message, but
for the advice on avoiding future problems.

GrandpaB
Nov 21 '05 #3

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

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
6
by: NewToDotNet | last post by:
I am getting "Object reference not set to an instance of an object. " when I attempt to open a C# windows service class in design view, although I was able to initially create the service and open...
1
by: Dave | last post by:
Hello I hope someone can give me some idea of what is causing this error. I can run though my asp app locally no problem but when i put it on the server i get this error, any help at all whould be...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
3
by: nemo | last post by:
Hi, My application works fine on the localhost but spits this error as soon as I put it on the server. I know this error occurs when an object has not been instantiated prior to a reference, but...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
7
by: Brett | last post by:
I'm not sure why I keep getting this error, "Object reference not set to an instance of an object". Private Function somefunction() as string Dim MyCurrentClass As New Class1 Try For i As...
6
by: kalaivanan | last post by:
hi, i am a beginner in c#. i have theoretical knowledge about object, reference and instance. but i want to know clearly about what is an object, reference and instance. can any one help me? or...
4
by: livmacca | last post by:
Hi, I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work: ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
1
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.