|
-
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
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
|