Summer's clearly been too long.
Alright, I have two separate classes. One contains my main() method and an arraylist of Song objects. The Song objec开发者_运维问答t has a method in it that needs to access the arraylist from the original class. The arraylist is public. I created an instance of the first class, called "guide", and tried to call the arrayList as shown:
Song temp = guide.songList...;
with no luck (couldn't resolve "guide"). I also tried it without "guide." with no success (couldn't resolve songList).
Both classes are in separate files but in the same /src folder (default package). Any ideas? I feel like I'm just overlooking something really stupid that I've forgotten over the summer.
For whatever reason you are out of scope of the guide
variable. You should review this and this to refresh your knowledge about variables.
It looks like your design is wrong. If the Song object is a part of the list, why does it need access to the whole list? Do you want to search similar songs?
You might want to have a SongManager (or SongCollection or similar) object which holds the list, and then give each Song a reference to its manager.
精彩评论