Terry Rogers
asked on
ArrayList in VB.NET Class
I am creating my first ever custom class.
Code currently us...
This is a class based upon http://www.aql.com/sms/integrated/sms-api/
I have set Destination as an ArrayList as it should be able to contain multiple destination numbers.
I have declared in my progect code as follows...
However I get the error...
System.NullReferenceExcept ion was unhandled
Message=Object reference not set to an instance of an object.
Source=WindowsApplication1
StackTrace:
at WindowsApplication1.frmCla ssView.btb SMS_Click( Object sender, EventArgs e) in C:\Users\terry\AppData\Loc al\Tempora ry Projects\WindowsApplicatio n1\frmClas sView.vb:l ine 5
at System.Windows.Forms.Contr ol.OnClick (EventArgs e)
at System.Windows.Forms.Butto n.OnClick( EventArgs e)
at System.Windows.Forms.Butto n.OnMouseU p(MouseEve ntArgs mevent)
at System.Windows.Forms.Contr ol.WmMouse Up(Message & m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Contr ol.WndProc (Message& m)
at System.Windows.Forms.Butto nBase.WndP roc(Messag e& m)
at System.Windows.Forms.Butto n.WndProc( Message& m)
at System.Windows.Forms.Contr ol.Control NativeWind ow.OnMessa ge(Message & m)
at System.Windows.Forms.Contr ol.Control NativeWind ow.WndProc (Message& m)
at System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Unsaf eNativeMet hods.Dispa tchMessage W(MSG& msg)
at System.Windows.Forms.Appli cation.Com ponentMana ger.System .Windows.F orms.Unsaf eNativeMet hods.IMsoC omponentMa nager.FPus hMessageLo op(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoopInner (Int32 reason, ApplicationContext context)
at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoop(Int3 2 reason, ApplicationContext context)
at Microsoft.VisualBasic.Appl icationSer vices.Wind owsFormsAp plicationB ase.OnRun( )
at Microsoft.VisualBasic.Appl icationSer vices.Wind owsFormsAp plicationB ase.DoAppl icationMod el()
at Microsoft.VisualBasic.Appl icationSer vices.Wind owsFormsAp plicationB ase.Run(St ring[] commandLine)
at WindowsApplication1.My.MyA pplication .Main(Stri ng[] Args) in 17d14f5c-a337-4978-8281-53 493378c107 1.vb:line 81
at System.AppDomain._nExecute Assembly(R untimeAsse mbly assembly, String[] args)
at System.AppDomain.ExecuteAs sembly(Str ing assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.Hos tingProces s.HostProc .RunUsersA ssembly()
at System.Threading.ThreadHel per.Thread Start_Cont ext(Object state)
at System.Threading.Execution Context.Ru n(Executio nContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.Execution Context.Ru n(Executio nContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHel per.Thread Start()
InnerException:
at the
line.
Why, and how do I fix this to work as I expect it to?
Code currently us...
Public Class AQL_SMS
Public Username As String
Public Password As String
Public Destination As ArrayList
Public Message As String
Public Originator As String
Public Max_Concat As String
Public Sendtime As Date
Public Unix_Sendtime As Integer
Public ReplaceSMS As Boolean
Public Flash As Boolean
Public Dlr_URL As String
Public Sub New(ByVal _username As String, ByVal _password As String)
Username = _username
Password = _password
End Sub
Public ReadOnly Property Destinations As String
Get
Dim tmpjoin As String = ""
Dim str As String
For Each str In Destination
tmpjoin = String.Concat(tmpjoin, str.ToString & ",")
Next
tmpjoin = tmpjoin.Substring(0, tmpjoin.Length - 1)
Return tmpjoin
End Get
End Property
End Class
This is a class based upon http://www.aql.com/sms/integrated/sms-api/
I have set Destination as an ArrayList as it should be able to contain multiple destination numbers.
I have declared in my progect code as follows...
Public Class frmClassView
Public SMS As New AQL_SMS("my_username", "my_password")
Private Sub btbSMS_Click(sender As System.Object, e As System.EventArgs) Handles btbSMS.Click
SMS.Destination.Add("01234567891")
SMS.Destination.Add("01234567891")
tmrAutoSMSPropertyCheck.Start()
End Sub
Private Sub tmrAutoSMSPropertyCheck_Tick(sender As System.Object, e As System.EventArgs) Handles tmrAutoSMSPropertyCheck.Tick
lblUsername.Text = SMS.Username
lblPassword.Text = SMS.Password
lblDestination.Text = SMS.Destinations
lblMessage.Text = SMS.Message
lblOriginator.Text = SMS.Originator
lblMax_Concat.Text = SMS.Max_Concat
lblSendtime.Text = SMS.Sendtime
lblUnix_Sendtime.Text = SMS.Unix_Sendtime
lblReplaceSMS.Text = SMS.ReplaceSMS
lblFlash.Text = SMS.Flash
lblDlr_URL.Text = SMS.Dlr_URL
End Sub
End Class
However I get the error...
System.NullReferenceExcept
Message=Object reference not set to an instance of an object.
Source=WindowsApplication1
StackTrace:
at WindowsApplication1.frmCla
at System.Windows.Forms.Contr
at System.Windows.Forms.Butto
at System.Windows.Forms.Butto
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Butto
at System.Windows.Forms.Butto
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Nativ
at System.Windows.Forms.Unsaf
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at Microsoft.VisualBasic.Appl
at Microsoft.VisualBasic.Appl
at Microsoft.VisualBasic.Appl
at WindowsApplication1.My.MyA
at System.AppDomain._nExecute
at System.AppDomain.ExecuteAs
at Microsoft.VisualStudio.Hos
at System.Threading.ThreadHel
at System.Threading.Execution
at System.Threading.Execution
at System.Threading.ThreadHel
InnerException:
at the
SMS.Destination.Add("01234567891")
line.
Why, and how do I fix this to work as I expect it to?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked perfectly. Thankyou! :)
1.This line
Open in new window
should give you an error as it should beOpen in new window
2. you have to create your ArrayList (or initialise it) then pass it to your initialised class,e.gOpen in new window
orOpen in new window