aspose file tools*
The moose likes Beginning Java and the fly likes Reading Objects from ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading Objects from ArrayList" Watch "Reading Objects from ArrayList" New topic
Author

Reading Objects from ArrayList

James Dudley
Greenhorn

Joined: May 20, 2011
Posts: 17
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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



[Jess in Action][AskingGoodQuestions]
James Dudley
Greenhorn

Joined: May 20, 2011
Posts: 17
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

Joined: Apr 06, 2011
Posts: 96

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reading Objects from ArrayList