• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to print the contents of a java bean  RSS feed

 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • 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.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 90
  • Mark post as helpful
  • send pies
  • 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"
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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: 90
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!