|
-
Dec 7th, 2011, 01:54 PM
#1
Thread Starter
New Member
NullReferenceException in my Project
Hey guys,
At first, sorry for my English, I am German .
So, concering my project: I am trying to control an RC Car via Kinect, until now I got it working with key control only (eg WASD). So, I am using a Velleman K8055 Interface Board + the Kinect and VB Windows Forms. So far, so good, I created 4 Forms: menu, info, kinect-controls + wasdcontrols window. The error only occurs for my kinect-controls window (german name: Steuerung.vb) & that's my source code:
Code:
Imports Microsoft.Research.Kinect.Nui
Imports System.Text
Imports Coding4Fun.Kinect.WinForm
Imports System.Xml.Serialization
Imports System.IO
Public Class Steuerung
Private Pointer = PictureBox2
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Function CloseDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub ClearAllDigital Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Dim nui As New Runtime()
Public Sub New()
InitializeComponent()
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
nui.Initialize(RuntimeOptions.UseSkeletalTracking)
SetupKinect()
AddHandler nui.SkeletonFrameReady, AddressOf nui_SkeletonFrameReady
AddHandler Runtime.Kinects.StatusChanged, AddressOf Kinects_StatusChanged
End Sub
Private Sub SetupKinect()
If Runtime.Kinects.Count = 0 Then
Label2.Text = "Keine Kinect angeschlossen"
Else
'use first Kinect
nui = Runtime.Kinects(0)
nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking)
End If
End Sub
Private Sub Kinects_StatusChanged(sender As Object, e As StatusChangedEventArgs)
Dim message As String = "Status geändert: "
Select Case e.Status
Case KinectStatus.Connected
message += "Verbunden"
Exit Select
Case KinectStatus.Disconnected
message += "Getrennt"
Exit Select
Case KinectStatus.[Error]
message += "Error"
Exit Select
Case KinectStatus.NotPowered
message += "Keine Stromversorgung"
Exit Select
Case KinectStatus.NotReady
message += "Nicht bereit"
Exit Select
Case Else
If e.Status.HasFlag(KinectStatus.[Error]) Then
message += "Kinect Error"
End If
Exit Select
End Select
Label2.Text = message
End Sub
Private Sub nui_SkeletonFrameReady(ByVal sender As Object, ByVal e As SkeletonFrameReadyEventArgs)
Dim allSkeletons As SkeletonFrame = e.SkeletonFrame
Dim skeleton As SkeletonData = ( _
From s In allSkeletons.Skeletons _
Where s.TrackingState = SkeletonTrackingState.Tracked _
Select s).FirstOrDefault()
Dim HandRight = skeleton.Joints(JointID.HandRight).ScaleTo(320, 240, 0.5F, 0.5F)
SetEllipsePosition(skeleton.Joints(JointID.HandRight))
End Sub
Private Sub SetEllipsePosition(ByVal joint As Joint)
Dim scaledJoint = joint.ScaleTo(320, 240, 0.5F, 0.5F)
PictureBox2.Left = scaledJoint.Position.X
PictureBox2.Top = scaledJoint.Position.Y
End Sub
Private Sub Hauptmenübutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hauptmenübutton.Click
Hauptmenü.Show()
nui.Uninitialize()
Label1.Text = "Nicht verbunden"
Me.Hide()
End Sub
Private Sub Infobutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Infobutton.Click
Info.Show()
Me.Hide()
End Sub
Private Sub Verbindenbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Verbindenbutton.Click
Dim CardAddress As Integer
Dim h As Integer
CardAddress = 2
h = OpenDevice(2)
Label1.Text = "Karte " + Str(h) + " angeschlossen"
End Sub
End Class
So, my error is concerning this line in the bottom third:
Code:
Dim HandRight = skeleton.Joints(JointID.HandRight).ScaleTo(320, 240, 0.5F, 0.5F)
and it says:
NullReferenceException [wurde nicht von Benutzercode behandelt.] (means: unhandled by user code.)
Object reference not set to an instance of an object.
What I tried so far:
1) Re-creating & cleaning up my project files (was promised to be the solution when I googled this)
2) Defining Dim HandRight in my Declarations
3) Setting HandRight to "Nothing"
but however, nothing will help :/
By the way, I am using the Coding4Fun.Kinect.WinForm.dll & the Microsoft.Research.Kinect.dll
If I forgot to mention anything important, please tell me.
Kind regards,
alex
-
Dec 7th, 2011, 03:22 PM
#2
Re: NullReferenceException in my Project

If I'm understanding the question right...
It could be either the skeleton object or the skeleton.Joints(JointID.HandRight) object that are null references, or 'Nothing' as they are referred to in VB. When the code breaks at that line, highlight those objects and right click and choose 'immediate watch'. Once you know which object is null, then you'll have a better idea of what to do to fix it.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Dec 7th, 2011, 04:41 PM
#3
Thread Starter
New Member
Re: NullReferenceException in my Project
I think I can now say this error is definitely caused by skeleton.Joints(JointID.HandRight), immediate watch tells me the following
Code:
HandRight = skeleton.Joints(JointID.HandRight) Der =-Operator ist für die Typen "Microsoft.Research.Kinect.Nui.Joint" und "Microsoft.Research.Kinect.Nui.Joint" nicht definiert.
which means something like
Code:
The =-operator is not defined for type "Microsoft.Research.Kinect.Nui.Joint" and "Microsoft.Research.Kinect.Nui.Joint".
. Because this is the only line containing an error I would conclude that this is what causes my problem.. But what can I do to fix this? Sorry, but I am quite new to Visual Basic :/ If this says that for Microsoft.Research.Kinect.Nui.Joint I cannot use "=-", I do not know why this error occurs because I have not even once used this.
Thanks for your patience 
Kind regards,
alex
-
Dec 7th, 2011, 04:49 PM
#4
Re: NullReferenceException in my Project
I'm confused. From the code it appears it's using the "=" operator, not the "=-" operator. I know why it would give you that error if you used it. That operator is a mathematical assignment operator - used to subtract one number from an existing number. For example:
Code:
Dim X as integer = 4
X =- 1
'X now equals 3
But it makes no sense to try to subtract an object from an object.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Dec 7th, 2011, 05:00 PM
#5
Re: NullReferenceException in my Project
When you get this error, examine each object in turn. In that line, there are only a few of them:
1) HandRight, but this can't cause the error.
2) skeleton
3) skeleton.Joints(JointID.HandRight)
To examine them, highlight each in turn and press Shift+F9. One of them is Nothing, and that one is your problem. That's always the first step for the original error message. Once you determine which one is Nothing (it sounds like it is the third one, in this case), then the next step is to figure out why that is Nothing.
In that case, it appears like skeleton.Joints is a method that takes an identifier and returns an object (probably an object of type joint, but I don't know kinect). The object is nothing, which suggests that there isn't a joint with the identifier JointID.RightHand. So why not? I'm not sure that any of us can say.
Is it possible that the particular item shouldn't exist in the setting you are working with?
My usual boring signature: Nothing
 
-
Dec 7th, 2011, 05:17 PM
#6
Thread Starter
New Member
Re: NullReferenceException in my Project
Ok, I now applied the immediate watch on skeleton.Joints only and the following came up confirming your statement that this is null.
Code:
skeleton.Joints Das referenzierte skeleton-Objekt hat den Wert "Nothing". Microsoft.Research.Kinect.Nui.JointsCollection
means
Code:
skeleton.Joints The referenced skeleton-object has the value "Nothing". Microsoft.Research.Kinect.Nui.JointsCollection
Is it possible that the particular item shouldn't exist in the setting you are working with?
I think it should, but I am not completely sure about this. I found big fragments of this code here and used them for this program.
But as they are working in c sharp/ vb wpf I don't exactly know if this will work out for WinForms...
Kind regards,
alex
Tags for this Thread
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
|