• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JTable and getValueAt()  RSS feed

 
Ranch Hand
Posts: 102
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am experimenting with the getValuAt() method. When I use the following:


... I get what I expect... Row2-Column1 ...ect.

However, when I save to file using:


... and then read it back in, the object doesn't seem to be the same type of object.
When I use System.out.println to view out put I get something like [Ljava.lang.Object;@1e4457d,
and I can't cast it to String.

What do I need to do to figure out how to use the data returned from file?

Here is the code not including the file read and write methods.

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Geoff Jefferson wrote:Here is the code not including the file read and write methods.



Heh, I'd say that's the opposite of what we need. We only need to see the code you're using to read and store the data.

By the way, is there any particular reason you're doing your looping backwards instead of counting up from 0?
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'll work on it some more.
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're writing an Object[] to file and that's what you get back.
 
Sheriff
Posts: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Geoff Jefferson wrote:[Ljava.lang.Object;@1e4457d,


That's an Object[]. You can tell:
- [ indicates it's an array
- Ljava.lang.Object; indicates it's an array of java.lang.Object; likewise, [Ljava.lang.String; would be a String[]
- @ is part of Object.toString()
- the remainder is the hexadecimal hash code of the array
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob, your explantion solved my problem.

G.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...until now. When I use the array as an argument to a method and then us Object.toString()

I still get [Ljava.lang.Object;@e24e2a.

 
Marshal
Posts: 24488
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 43 is your problem?

You have an array of Object[] objects. You iterate through that array and yes, each of the elements of the array is an Object[] object. Which is exactly what you are seeing. No surprise there.

You just seem to have assumed that the for-loop, when applied to an array of arrays, would automatically drill down to the lowest level. You're making things too complicated if that's what you assumed. A for-loop, when applied to an array of X, always iterates over each X in the array. If X happens to be Object[] -- as in this case -- then that's what it is. Nothing different happens.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> You're making things too complicated if that's what you assumed.

I do have a tendancy to make things more difficult.
I re-wrote the loop and everything is working as exected.

Thank you.
G.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please bear with me. Even though I got the results I was looking for in this example. I am still a little unclear
on what my output was someting like ... [Ljava.lang.Object;@1e0bc08

What is the a representation of the index of the array?

 
Paul Clapham
Marshal
Posts: 24488
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Geoff Jefferson wrote:Please bear with me. Even though I got the results I was looking for in this example. I am still a little unclear
on what my output was someting like ... [Ljava.lang.Object;@1e0bc08

What is the a representation of the index of the array?



I'm sorry, I think I need an English translation of that last sentence.

However, picking out a bit I can understand: "the index of the array". There's nothing in that output which has anything to do with indexes of any array. What you have there is simply a representation of an object which happens to be of the type Object[].
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why couldnt I cast it to string?
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Geoff Jefferson wrote:Why couldnt I cast it to string?



You are calling toString on an array, not on a String. Remember that a 2-d array of anything is an array of arrays. So if you want to see what the row is holding, you have to either loop through the sub array or use Arrays.toString to see it:
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
Oh. Hi guys! Look at this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!