这是我检测机器上JDK安装功能的代码。 执行代码提供了处理的异常: -
第164行是: - If ndpKey Is Nothing AndAlso ndpKey.GetValue("CurrentVersion") Is Nothing Then
Private Function HAS_JDK() As Boolean
Try
Const subkeyjava As String = "SOFTWARE\JavaSoft\Java Runtime Environment"
Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkeyjava)
If ndpKey Is Nothing AndAlso ndpKey.GetValue("CurrentVersion") Is Nothing Then
Close()
Return False
Else
Return True
End If
End Using
Catch e As NullReferenceException
MessageBox.Show("System Error Occured While Checking JDK !! ", "BLA BLA BLA - Error Occured !!")
MessageBox.Show(e.ToString())
Close()
Return -1
End Try
End Function
答案 0 :(得分:3)
你的逻辑有点不正确。我认为你所追求的是OrElse
:
If ndpKey Is Nothing OrElse ndpKey.GetValue("CurrentVersion") Is Nothing Then
这会检查 ndpKey
或 ndpKey.GetValue("CurrentVersion")
是否属实。如果第一次检查成功,它将不会继续第二次,因此也不例外。