Android Question Reflection vs JavaObject

OliverA

Expert
Licensed User
Longtime User
How come this works:

B4X:
Public Sub Initialize (server As FTPServer, socket As Socket, DataPort As Int)
    '... some code ...
    Dim r As Reflector
    r.Target = socket
    r.Target = r.GetField("socket")
    ' ... more code ...

(The code above is taken from https://www.b4x.com/android/forum/threads/how-do-the-serversocket-look-up-the-ip-address-of-the-connected-client.28875/#post-167644)

But
B4X:
Public Sub Initialize (server As FTPServer, socket As Socket, DataPort As Int)
    '... some code ...
    Dim jo AsJavaObject = socket
    jo = jo.GetField("socket")
    '... more code...

Throws

java.lang.RuntimeException: Field: socket not found in: anywheresoftware.b4a.objects.SocketWrapper
in B4A?

BTW, the same JavaObject code works fine in B4J.

Note: I'm modifying the FTP Server code (the FTPClient Initialize method). So if you need a running project, that is it (found here: https://www.b4x.com/android/forum/t...d-with-socket-and-asyncstreams.74320/#content)
 
Top