Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating JTable using data from .txt file

 
boki markos
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can compile, the JTable is created and so are the column headings but the rows arent... in the rows this comes up : [Ljava.lang.String;@408fbecf <--- these numbers change on every cell
i think the problem is with the getValueAt() class... can someone please help me out.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boki markos wrote:[Ljava.lang.String;@408fbecf <--- these numbers change on every cell

That is the result of toString() called on a String[].

You probably want to return rosterList.get(row)[column] in getValueAt - rosterList.get(row) returns a String[], and you take element column of that array.

Of course you will need a cast to String[] if you're not using generics.
 
boki markos
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, thanks for reply... umm i am pretty new to java, what is a cast to String[]? :S

i changed

rosterList.get(row)[col] and i still get an error
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out http://www.janeg.ca/scjp/oper/cast.html

Because your ArrayList does not use generics, rosterList.get(row) returns an Object reference. You need to cast that to String[] first, before you can access its elements.

Or you can make your ArrayList generic; check out http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
 
Campbell Ritchie
Sheriff
Pie
Posts: 50226
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We usually discuss this sort of question on the Swing forum. Moving.
 
boki markos
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dont get that generics stuff lol

anyother way to do it?

can you show me what i need to change please?
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you even read that first link?
 
boki markos
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this what you ment? i changed my ArrayList... the program now compiles and runs but no rows.. just the headings(columns)
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's from the second link, but to be honest, generics are better.

What are the contents of rosterList? Is the file read properly?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic