Class cls = stream.getClass(); Field addressField = cls.getDeclaredField("address"); Field portField = cls.getDeclaredField("port"); this.dataAddress = (InetAddress)addressField.get((RecvSSRCInfo)stream); this.dataPort = portField.getInt((RecvSSRCInfo)stream);
stream is of type com.sun.media.rtp.RecvSSRCInfo
In Eclipse on Expressions window(watch) I see the fileds address and port of stream object, they have the expected values also but when I try to get these values using reflection it throws NoSuchFieldException.
The address and port fields may be declared in a superclass of the class you're looking at. The getDeclaredXXX() methods only look for things declared in that particular class. You need to check up the inheritance tree yourself using getSuperclass().
Hi! Thanks for pointing out that the fields might be in a super class. They were!
Also I would like to add that the fileds were package accessible (no access modifier: private, public or protected infront of them). So to be able to get them I set the accessible flag of each field to true: