• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading Objects from ArrayList

 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have passed an ArrayList to a new Swing Class to print out the values within the ArrayList

My trouble is that I cannot work out how to read the Object Values back from the ArrayList

This is the Swing Class. The ScoreEnd is a class Object in other part of the code
The pScorePadTotals is being passed to this class from a different class when a button is pressed


Thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on what you need to do, ArrayList has methods named size() and get() which tell you how many items are in the list and return one item given its integer position in the list, respectively, or you can use a for-loop to process all the items, something like

 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

I have done that but getting an error "score1 is not public in PackageName.ScoreEnd; Cannot be accessed outside package"
I have imported the package the ScoreEnd class is in
Looking in the ScoreEnd Class and all the elements are public. Well the class is public I left the elements to be default.
 
Wim Vanni
Ranch Hand
Posts: 96
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Dudley wrote:... I left the elements to be default.


See here for some explanation about 'default modifiers' for class attributes. Chances are you simply have no access. It is a good practice to define members/attributes as private and define getter and setter methods for them.

Cheers,
Wim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic