Object reference not set to an instance of an object.?
-
I tried to show my Form2 by calling Form2.Show() but it says Object reference not set to an instance of an object. What do I do? Form2 code below: Public Class Form2 Dim location_rock As Integer = RectangleShape1.Location.Y Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) Private Sub Form2_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.J Then PictureBox1.Location = New Point(75, PictureBox1.Location.Y) End If End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Button1.Visible = False Call rockmove() End Sub Private Sub rockmove() Do Until RectangleShape1.Location.Y = 529 location_rock = location_rock + 2 RectangleShape1.Location = New Point(RectangleShape1.Location.X, location_rock) Sleep(300) Loop End Sub End Class
-
Answer:
statements like this could be the cause: location_rock = location_rock + 2 if location_rock had a null value if it's happening when calling .show() it could even be that the Form2 object is null and hasn't been instantiated. Try to debug and look for variables that are null
Interesting Articles at Yahoo! Answers Visit the source
Related Q & A:
- Is Java pass by value or pass by reference?Best solution by Stack Overflow
- How to properly reference a user control and dynamically add it to page?Best solution by Stack Overflow
- Object reference not set to an instance of an object; null?Best solution by Stack Overflow
- How to close instance of an XML DOCUMENT?Best solution by Stack Overflow
- What is difference between instance class and static class in c#?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.