Question: VISUAL BASIC VISUAL BASIC I am getting sn error 'NullReferenceException as shown in the image below. It is when the user's input is trying to
VISUAL BASIC VISUAL BASIC I am getting sn error 'NullReferenceException" as shown in the image below. It is when the user's input is trying to write to the file. Why am I receiving this error? What shoud I do to fix it?
Here is the code for my 'save to file' button
Dim fileName As String fileName = Directory.GetCurrentDirectory() & "/travel.ser"
output = New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)
Dim record As New TravelRecord()
record.ID = Guid.NewGuid() record.FirstName = FirstNameBox.Text record.LastName = LastNameBox.Text record.Purpose = PurposeBox.Text record.StartDate = StartDateBox.Text record.EndDate = EndDateBox.Text record.Amount = Convert.ToDecimal(AmountBox.Text)
'write record to file fileWriter.WriteLine(record.ID.ToString() & "," & record.FirstName & "," & record.LastName & "," & record.Purpose & "," & record.StartDate & "," & record.EndDate & "," & record.Amount)

| 11 NullReferenceException + v 2Quick Launch (Ctri-Q) D TravelRequest (Debugging) -Microsoft Visual Studio File Edit View Project Build Debug Team ToolsTest Analyze Window Help Brittany Lash BL NETProcess: [13072 TravelRequest.vshost.exe Lifecycle Events Thread: [10484] Main Thread Stack Frame: TravelRequest. TravelRequestForm.btnSave RequestList.vb m] Trave!Request frmTravel.vbX frm Travel.vb [Design)] btnSave RequestList.vb Design] Diagnostic Tools Click Select Tools 'Q Zoom In Zoom Out il' Reset View Diagnostics session: 13 seconds (13.008 s selected) 197 198 199 288 281 202 283 284 285 286 record. FirstName = FirstNameBox . Text record.Lastllame LastNameBox.Text record.Purpose PurposeBox. Text record. StartDate = StartDateBox-Text record. EndDate = EndDateBox . Text NullReferenceException was unhandled An unhandled exception of type "System.NullReferenceException' occurred in record.Amount Convert.ToDecimal(AmountBox. Text) Additional information: Object reference not set to an instance of an object. write record to file fileMriter.WriteLine(record. ID. Tostring & "& record.FirstilTroubleshooting tips & record.StartDate record.Purpose &"& recohd. Amount) "," && 288 289 210 211 212 Check to determine if the object is null before calling the method. Use the "new" keyword to create an object instance Get general help for this exception. Search for more Help Online... End If Thread Try ValidateNotBlank (FirstNameBox) 00% | Exception settings: Break when this exception type is thrown Value (TravelRequest. TravelRequestForm, Text: Travel Request Tet"Save Request' (X = 54 Y = 4 Button = Left (1048576)) CAUsersi britt-Desktop\TravelRequestTravelRequ Nritins Actions: View Detail.. Me sender fileName record myGuid Watch 1 Copy exception detail to the clipboard scription est bin Debug/Open exception setting a values Caneltui ronflirts with 171e6c0e002 brittany lash vaca11/20/2018 11/28/2018 $30000)eu { 62c6794-40cf-4047-8f65-0171 0e002) Locals Ln 207 Col 38 Ch 38 YesNo /I The example displays output like the following output: 4:55 PM O Type here to search 118/2018 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
