| Author |
creating JTable using data from .txt file
|
boki markos
Greenhorn
Joined: May 10, 2009
Posts: 5
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
boki markos
Greenhorn
Joined: May 10, 2009
Posts: 5
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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
Joined: Oct 13, 2005
Posts: 32712
|
|
|
We usually discuss this sort of question on the Swing forum. Moving.
|
 |
boki markos
Greenhorn
Joined: May 10, 2009
Posts: 5
|
|
dont get that generics stuff lol
anyother way to do it?
can you show me what i need to change please?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Have you even read that first link?
|
 |
boki markos
Greenhorn
Joined: May 10, 2009
Posts: 5
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
That's from the second link, but to be honest, generics are better.
What are the contents of rosterList? Is the file read properly?
|
 |
 |
|
|
subject: creating JTable using data from .txt file
|
|
|