• 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

How to print the contents of a java bean

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to debug a program and I need to see the values in a Bean. I tried " System.out.println("OrderManager.java: packagePricing, packBean="+packBean);" but that just gives me "OrderManager.java: packagePricing, packBean=com.voxportal.web.device.PackageBean@73dde7ae" which I think is a reference to the bean but not the actual contents of the Bean.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to override the toString() method of that class. ToStringBuilder can facilitate that.
 
Michael Piaser
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to make my print request more specific. When I use " System.out.println("OrderManager.java: packagePricing, packBean.retailPrice="+packageBean.retailPrice.toString());" I get an error "[ERROR] \VOX\voxware-1.1.14\voxportal\voxportal-web\src\main\java\com\voxportal\web\device\OrderManager.java:[1677,95] error: retailPrice has private access in PackageBean"

I don't know what "private access" in a bean means. The getter says "public"
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, but the member variable retailPrice itself is private. That means that you cannot access it directly outside the class in which is defined. Call the getter instead of accessing the member variable directly:

See: Controlling Access to Members of a Class

But you've changed what you are doing from the original problem that you had, for which Junilu proposed a solution: implement a toString() method in class PackageBean.
 
Michael Piaser
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I have changed from the original problem as I'm trying to get a simple value from the bean. I found out what the "private access" error is - I have to reference the Getter instead of the name.
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic