• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Big Reflection Problem(Eclipse sees values Reflection don't)

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have this code:

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.

Can anyone please help with this?

Thank you!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getDeclaredField() will return a Field only if the field is defined in the exact class you're probing, but not if it's defined in a superclass. Are you sure the fields aren't defined in a superclass?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EFH, this is revenge for yesterday, isn't it?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup
 
Ioan Berciu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

addressField.setAccessible(true);
portField.setAccessible(true);

Only afthere setting true on accessible flag I was able to get the values
Thanks all for repllying so quick.
reply
    Bookmark Topic Watch Topic
  • New Topic