Jump to content

Help - "Object reference not set to an instance of an object."

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Wisey

Wisey

    Newbie

  • Members
  • Pip
  • 1 posts
I'm having a bit of trouble with a error I'm getting from vb. It's a mock up of a game rental company. I'm getting it at the line "itemTitle = borrowing.getLoan(loanID).getBorrowedItem.getTitle" loanID is populated and so should be all the attributes of the loan. All the get functions just return the appropriate attribute. I'm using VB 2008.

Error:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."

Form code:
Dim loanID As Integer
Dim itemID As Integer
Dim itemTitle As String
Dim itemBorrower As String
Dim itemStaffTaken As String
Dim dueDate As Date

If loanSelected = True Then
            loanID = loanList.Items(loanPosition)
            itemTitle = borrowing.getLoan(loanID).getBorrowedItem.getTitle
            itemID = borrowing.getLoan(loanID).getBorrowedItem.getBarcode
            itemBorrower = borrowing.getLoan(loanID).getBorrower.getName
            itemStaffTaken = borrowing.getLoan(loanID).getStaffInvolved.getStaffName
            dueDate = borrowing.getLoan(loanID).getDueDate
            MessageBox.Show("--Loan Info--" & vbCr & loanID & vbCr & itemID & vbCr & itemTitle & vbCr & itemBorrower & vbCr & itemStaffTaken & vbCr & dueDate)
End If

Top form code:
Private borrowing As New OnlOan()
Private loanPosition As Integer
Private loanSelected As Boolean = False
Private aLoan As LoanItem

Loan list item selected:
loanPosition = loanList.SelectedIndex
loanSelected = True

Obviously thats not all the code, I can provide more if needed. I don't know if anyone can help me or not. It might just be something simple, or a massive flaw in my code - I just don't know. I can't get my head round it.

Any help is appreciated, thanks in advance!

Edited by Wisey, 26 April 2010 - 06:45 AM.


#2
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
use the New to define an instance of an object????
Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel