• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 24204
44
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: 24204
44
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.
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic