Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and getValueAt()

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • 0
  • 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.

 
Kevin Workman
Ranch Hand
Posts: 151
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'll work on it some more.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.

 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why couldnt I cast it to string?
 
pete stein
Bartender
Posts: 1561
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic