• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

creating JTable using data from .txt file

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you even read that first link?
 
boki markos
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic