• Post Reply Bookmark Topic Watch Topic
  • New Topic

response com.STRING@4fbc7b65 instead of the actual data, is it memory address instead of value?  RSS feed

 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a program while writing data to a file, I am getting value response com.STRING@4fbc7b65 instead of the actual data, is it memory address instead of value?. By this can I know the mistake I am doing because it is displaying memory address instead of data. I know one such case that if there is an array and you are displaying it as it is instead of displaying array elements, it shows the memory address instead of value.Are there any other such mistakes which can lead to this? I tried using a toString() at the end of what I was printing but still got the same problem.

thanks
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monica. Shiralkar wrote:is it memory address instead of value?

No. It's almost certainly the hashcode. Whether that helps you to work things out or not I have no idea.

And the reason you're seeing it is that the class of the object being displayed doesn't override toString().

HIH

Winston
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monica. Shiralkar wrote:In a program while writing data to a file, I am getting value response com.STRING@4fbc7b65 instead of the actual data, is it memory address instead of value?. By this can I know the mistake I am doing because it is displaying memory address instead of data. I know one such case that if there is an array and you are displaying it as it is instead of displaying array elements, it shows the memory address instead of value.Are there any other such mistakes which can lead to this? I tried using a toString() at the end of what I was printing but still got the same problem.


The toString() method for the Object class returns the name of the class and the identity hash. So, if you want the toString() method to return a different result, you will need to override the method.

Henry
 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
The same kind of issue I had faced with another field and my mistake in that case was I was storing an element which was an array(instead of extracting fields of array and then storing).

But in this case doing the same didnt work(It is not an array)
 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:

So, if you want the toString() method to return a different result, you will need to override the method.


The same kind of issue I had faced with another field and my mistake in that case was I was storing an element which was an array(instead of extracting fields of array and then storing). So is there any relation between overriding the toString method in the case of array and the way it was resolved?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monica. Shiralkar wrote:my mistake in that case was I was storing an element which was an array(instead of extracting fields of array and then storing).

It may be worth mentioning that you can also display the contents of an array with Arrays.toString(array).

Winston
 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all. I figured it out. It is an array only. a byte array. I did Array.toString() and it worked fine.

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monica. Shiralkar wrote:Thanks all. I figured it out. It is an array only. a byte array. I did Array.toString() and it worked fine.


BTW, a byte array can never return a value of "com.STRING@4fbc7b65" from it's toString() method. So, either something has changed, so we are not clear of the original question.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!