|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Error: Object reference not set to an instance of an object.
An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
I'm trying to make a game for this class I'm taking. I started getting this error after trying to make an array of objects. In the game you're a tornado chaser, so I have a class for city and a class for the tornado. I'm not going to post my main form unless someone wants me to but it creates ten instances of city. Public Class City Public cityName As String Public cityNum As Integer Public temperature As Integer Public windSpeed As Integer Public nTemperature As Integer Public nWindSpeed As Integer Public sTemperature As Integer Public sWindSpeed As Integer Public wTemperature As Integer Public wWindSpeed As Integer Public eTemperature As Integer Public eWindSpeed As Integer Public weatherType As Integer = CInt(2 * Rnd() + 1) Public tornadoN(cityNum) As Object Public tornadoS(cityNum) As Object Public tornadoE(cityNum) As Object Public tornadoW(cityNum) As Object Public Sub New(ByVal name As String, ByVal num As Integer) cityName = name cityNum = num set_weather_type() End Sub Sub set_weather_type() If weatherType = 1 Then set_weather1() ElseIf weatherType = 2 Then set_weather2() ElseIf weatherType = 3 Then set_weather3() End If End Sub Sub set_weather1() temperature = CInt(90 * Rnd() + 70) windSpeed = CInt(5 * Rnd()) nTemperature = CInt(90 * Rnd() + 70) nWindSpeed = CInt(5 * Rnd()) sTemperature = CInt(90 * Rnd() + 70) sWindSpeed = CInt(5 * Rnd()) wTemperature = CInt(90 * Rnd() + 70) wWindSpeed = CInt(5 * Rnd()) eTemperature = CInt(90 * Rnd() + 70) eWindSpeed = CInt(5 * Rnd()) End Sub Sub set_weather2() temperature = CInt(60 * Rnd() + 40) windSpeed = CInt(18 * Rnd() + 1) nTemperature = CInt(60 * Rnd() + 40) nWindSpeed = CInt(18 * Rnd() + 1) Dim tornadoN(cityNum) As Tornado tornadoN(cityNum).set_tornado(weatherType) sTemperature = CInt(60 * Rnd() + 40) sWindSpeed = CInt(18 * Rnd() + 1) Dim tornadoS(cityNum) As Tornado tornadoS(cityNum).set_tornado(weatherType) wTemperature = CInt(60 * Rnd() + 40) wWindSpeed = CInt(18 * Rnd() + 1) Dim tornadoW(cityNum) As Tornado tornadoW(cityNum).set_tornado(weatherType) eTemperature = CInt(60 * Rnd() + 40) eWindSpeed = CInt(18 * Rnd() + 1) Dim tornadoE(cityNum) As Tornado tornadoE(cityNum).set_tornado(weatherType) End Sub Sub set_weather3() temperature = CInt(50 * Rnd() + 35) windSpeed = CInt(30 * Rnd() + 5) nTemperature = CInt(50 * Rnd() + 35) nWindSpeed = CInt(30 * Rnd() + 5) Dim tornadoN(cityNum) As Tornado tornadoN(cityNum).set_tornado(weatherType) sTemperature = CInt(50 * Rnd() + 35) sWindSpeed = CInt(30 * Rnd() + 5) Dim tornadoS(cityNum) As Tornado tornadoS(cityNum).set_tornado(weatherType) wTemperature = CInt(50 * Rnd() + 35) wWindSpeed = CInt(30 * Rnd() + 5) Dim tornadoW(cityNum) As Tornado tornadoW(cityNum).set_tornado(weatherType) eTemperature = CInt(50 * Rnd() + 35) eWindSpeed = CInt(30 * Rnd() + 5) Dim tornadoE(cityNum) As Tornado tornadoE(cityNum).set_tornado(weatherType) End Sub End Class Public Class Tornado Dim fLevel As Integer Dim speed As Integer Dim size As Integer Sub set_tornado(ByVal type) If type = 2 Then set_tornado2() Else set_tornado3() End If End Sub Sub set_tornado2() fLevel = CInt(3 * Rnd() + 1) If fLevel = 1 Then speed = CInt(90 * Rnd() + 70) size = CInt(80 * Rnd() + 60) ElseIf fLevel = 2 Then speed = CInt(70 * Rnd() + 50) size = CInt(60 * Rnd() + 40) Else speed = CInt(50 * Rnd() + 30) size = CInt(40 * Rnd() + 20) End If End Sub Sub set_tornado3() fLevel = CInt(5 * Rnd() + 4) If fLevel = 4 Then speed = CInt(120 * Rnd() + 90) size = CInt(110 * Rnd() + 80) Else speed = CInt(175 * Rnd() + 120) size = CInt(150 * Rnd() + 110) End If End Sub End Class |
|
#2
|
|||
|
|||
|
What is your question? What is not working? Any error message? What line is the error on? Step debug.
|
|
#3
|
|||
|
|||
|
An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
That is the error message i get. It doesn't tell me what line its on. In debug on the error list it says 0. I know it has something to do with the parts of the code where I make objects of the Tornado class, because it worked till I put those in there: Dim tornadoN(cityNum) As Tornado TornadoN(cityNum).set_tornado(weatherType) |
|
#4
|
|||
|
|||
|
Sorry, now I see the first line in your post does cover the error info. Hope someone else responds to your issue. I have no experience with user-defined classes and have absolutely no idea what 'Exception.InnerException' means, looking at MS help on the topic didn't clarify for me.
|
|
#5
|
|||
|
|||
|
I think I might know the problem. Is it possible to make an object within an object. because my program makes a city object in the main form then the city makes a tornado object.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Error: Object reference not set to an instance of an object. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|