【发布时间】:2015-06-21 22:10:02
【问题描述】:
我正在尝试创建一个简单的游戏,首先它需要随机加载 16 个带有图像的 PictureBox。我不确定问题出在哪里。
Public Class Form1
Private picArrows() As PictureBox = {pic11, pic12, pic13, pic14,
pic21, pic22, pic23, pic24,
pic31, pic32, pic33, pic34,
pic41, pic42, pic43, pic44}
Private Sub btnNew_Click(sender As Object, e As EventArgs) Handles btnNew.Click
'starts a new game
'declares RNG
Dim randGen As New Random
'uses RNG to determine arrow placement
For intPicBox As Integer = 0 To 15
Select Case randGen.Next(1, 5)
Case 1
picArrows(intPicBox).Image = My.Resources.Up
Case 2
picArrows(intPicBox).Image = My.Resources.Right
Case 3
picArrows(intPicBox).Image = My.Resources.Down
Case 4
picArrows(intPicBox).Image = My.Resources.Left
End Select
Next
End Sub
End Class
我在案例 X 之后的行上收到 NullReferenceException 错误。有人知道我在做什么错吗?
【问题讨论】:
-
你没有说哪里出了问题或错误是什么
-
我在 Case X 之后的行上收到 NullReferenceException 错误
-
你
picArrows()或picArrows(x)为空