REALBasic/Xojo NilObjectException When Calling Class Method From Property

402 views Asked by At

I'm writing a console application used for UDP-based chat.

I have a class called App whose Super is ConsoleApplication (the "main" class) and a UDPInterface class whose Super is EasyUDPSocket. In the App class, there is a property called UDP whose type is UDPInterface (UDP As UDPInterface). In the Run event handler, there is this code:

StdOut.WriteLine(UDP.GetIP)

UDPInterface's method GetIP consists of the following code (return type is String):

return LocalAddress

LocalAddress is an EasyUDPSocket method that simply retrieves the internal IP.

The problem I'm having is that when I call UDP.GetIP, the program returns a NilObjectException. I need to use the UDPInterface class as a property so its properties work the same across all the methods inside App.

1

There are 1 answers

0
Andrew Lambert On

Objects must be instantiated using the New keyword prior to use. An object which hasn't been instantiated will always be Nil, and using a Nil object will always raise a NilObjectException:

UDP = New UDPInterface
StdOut.WriteLine(UDP.GetIP)