|
-
Feb 26th, 2012, 12:56 AM
#1
Thread Starter
Lively Member
Null Exception Problem Wont go Away
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=Landlord Tycoon
StackTrace:
at Landlord_Tycoon.House_Information.btnUpgrade_1_Click(Object sender, EventArgs e) in C:\Users\Admin\documents\visual studio 2010\Projects\Landlord Tycoon\Landlord Tycoon\House_Information.vb:line 46
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Landlord_Tycoon.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Error on this line:
Code:
Game_Board.UpdateMoney()
From:
Code:
Private Sub btnUpgrade_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpgrade_1.Click
If Storage.HouseNumber = 1 Then
If Storage.PlayerMoney >= 1000 Then
Storage.PlayerMoney -= 1000
Storage.HomeValue += 500
HouseChecker()
Game_Board.UpdateMoney()
End If
End If
End Sub
Source code:
Board:
Code:
Public Class Game_Board
Private Storage As New Storage
Sub New(ByRef argstorage As Storage)
InitializeComponent()
storage = argstorage
Me.Show()
End Sub
Dim House_Information As House_Information
Private Sub GameBoard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Storage.NewGame = True Then
Storage.PlayerMoney = 5000
Storage.OwnProperty1 = True
End If
UpdateMoney()
End Sub
Private Sub House1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles House1.Click
Storage.HouseNumber = 1
'Prevents Multipal Windows being Open at once
If Storage.FormOpen = True Then
House_Information.Close()
House_Information = New House_Information(Storage)
Else
House_Information = New House_Information(Storage)
End If
End Sub
Public Sub UpdateMoney()
lblPlayerMoney.Text = Storage.PlayerMoney
End Sub
End Class
house Info Form:
Code:
Public Class House_Information
Private Storage As New Storage
Sub New(ByRef argstorage As Storage)
InitializeComponent()
storage = argstorage
Me.Show()
End Sub
Dim Game_Board As Game_Board
Private Sub House_Information_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'Prevents Multipal Windows being Open at once
Storage.FormOpen = False
End Sub
Private Sub House_Information_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Storage.FormOpen = True
HouseChecker()
End Sub
Public Sub HouseChecker()
If Storage.HouseNumber = 1 Then
'Home Value
Storage.HomeValue = 0 + Storage.HomeUpgrade
lblHouseValue.Text = Storage.HomeValue
'Address
lblHouseNumber.Text = "123 W Evergreen Lane"
If Storage.OwnProperty1 = True Then
btnSellHouse.Visible = True
btnSellHouse.Enabled = True
lblSellHouse.Visible = True
ElseIf Storage.OwnProperty1 = False Then
btnSellHouse.Visible = False
btnSellHouse.Enabled = False
lblSellHouse.Visible = False
End If
End If
End Sub
Private Sub btnUpgrade_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpgrade_1.Click
If Storage.HouseNumber = 1 Then
If Storage.PlayerMoney >= 1000 Then
Storage.PlayerMoney -= 1000
Storage.HomeValue += 500
HouseChecker()
Game_Board.UpdateMoney()
End If
End If
End Sub
End Class
Storage Class:
Code:
Public Class Storage
Public Shared intPlayerMoney As Integer
Public Shared intHouseNumber As Integer
Public Shared intGameBoard As Integer
Public Shared intHomeValue As Integer
Public Shared intHomeUpgrade As Integer
Public Shared bolOwnProperty1 As Boolean
Public Shared bolOwnProperty2 As Boolean
Public Shared bolOwnProperty3 As Boolean
Public Shared bolOwnProperty4 As Boolean
Public Shared bolOwnProperty5 As Boolean
Public Shared bolOwnProperty6 As Boolean
Public Shared bolNewGame As Boolean
Public Shared bolFormOpen As Boolean
Property PlayerMoney As Integer
Get
Return intPlayerMoney
End Get
Set(ByVal value As Integer)
intPlayerMoney = value
End Set
End Property
Property HouseNumber As Integer
Get
Return intHouseNumber
End Get
Set(ByVal value As Integer)
intHouseNumber = value
End Set
End Property
Property GameBoard As Integer
Get
Return intGameBoard
End Get
Set(ByVal value As Integer)
intGameBoard = value
End Set
End Property
Property HomeValue As Integer
Get
Return intHomeValue
End Get
Set(ByVal value As Integer)
intHomeValue = value
End Set
End Property
Property HomeUpgrade As Integer
Get
Return intHomeUpgrade
End Get
Set(ByVal value As Integer)
intHomeUpgrade = value
End Set
End Property
Property OwnProperty1 As Boolean
Get
Return bolOwnProperty1
End Get
Set(ByVal value As Boolean)
bolOwnProperty1 = value
End Set
End Property
Property OwnProperty2 As Boolean
Get
Return bolOwnProperty2
End Get
Set(ByVal value As Boolean)
bolOwnProperty2 = value
End Set
End Property
Property OwnProperty3 As Boolean
Get
Return bolOwnProperty3
End Get
Set(ByVal value As Boolean)
bolOwnProperty3 = value
End Set
End Property
Property OwnProperty4 As Boolean
Get
Return bolOwnProperty4
End Get
Set(ByVal value As Boolean)
bolOwnProperty4 = value
End Set
End Property
Property OwnProperty5 As Boolean
Get
Return bolOwnProperty5
End Get
Set(ByVal value As Boolean)
bolOwnProperty5 = value
End Set
End Property
Property OwnProperty6 As Boolean
Get
Return bolOwnProperty6
End Get
Set(ByVal value As Boolean)
bolOwnProperty6 = value
End Set
End Property
Property NewGame As Boolean
Get
Return bolNewGame
End Get
Set(ByVal value As Boolean)
bolNewGame = value
End Set
End Property
Property FormOpen As Boolean
Get
Return bolFormOpen
End Get
Set(ByVal value As Boolean)
bolFormOpen = value
End Set
End Property
End Class
Game Menu (not needed but here you go)
Code:
Public Class Game_Menu
Private Storage As New Storage
Dim GameBoard As Game_Board
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Storage.NewGame = True
GameBoard = New Game_Board(Storage)
Me.Close()
End Sub
End Class
Looking for a simple answer here. No errors but when I click on upgrade errors. Basicly a syntax error or something has a issue with me making a call to another form. I need to be able to make a call to that form to tell it to update the players money. Suggestions using the syntax Ive proveded would be very helpful thanks.
-
Feb 26th, 2012, 04:24 AM
#2
Addicted Member
Re: Null Exception Problem Wont go Away
Shot in the dark:
Code:
Public Sub UpdateMoney()
lblPlayerMoney.Text = Storage.PlayerMoney
End Sub
Doesn't know where to find lblPlayerMoney. Maybe initialize the board class to include the form by reference so it can find it. So something like form.lblPlayerMoney.Text = Storage.PlayerMoney
-
Feb 26th, 2012, 06:59 AM
#3
Re: Null Exception Problem Wont go Away
On the same assumption, perhaps
Code:
Public Sub UpdateMoney()
lblPlayerMoney.Text = Storage.PlayerMoney
End Sub
could become
Code:
Property PlayerMoney As Integer
Get
Return Storage.PlayerMoney
End Get
End Property
Then the line of the error
Code:
Game_Board.UpdateMoney()
could become
Code:
lblPlayerMoney.Text = Game_Board.PlayerMoney.ToString()
-
Feb 26th, 2012, 01:18 PM
#4
Thread Starter
Lively Member
Re: Null Exception Problem Wont go Away
The entire source code was posted above. the problem is its not letting me make calls to other forums because I set it up as a object. This right here is what is causing issues making calls to other forms.
Code:
Private Storage As New Storage
Sub New(ByRef argstorage As Storage)
InitializeComponent()
storage = argstorage
Me.Show()
End Sub
However, I need that snippet so it will update the form to match storage values. So now basilclly you can just make simple calls to other forums. There is a syntax error on my part I have to use a different syntax to make a call to aother form I just cant remember how.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|