Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Java I have an Array that cannot be resolved across a class without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I have an Array that is in a class called MusicArray and I want to be able to print its data and search it in my SearchClass class
import java.util.Arrays; import java.util.Scanner; public class Searchclass { public static void main(String[] args) { MusicArray ma = new MusicArray(); for(int count = 1; count <= songDetails.length; count++){ System.out.println(SongDetails.length); System.out.println(songDetails[count - 1]);}
In the MusicArray class I have this
public Music[] getSongDetails() { return songDetails;
I though that this code snippet made the array availabe to the other classes
What am I missing?
Answer
You need to use the ma
object to retrieve the array, like this:
Music[] songDetails = ma.getSongDetails();
Then you can iterate over the Music[]
array.
We are here to answer your question about Java I have an Array that cannot be resolved across a class - If you find the proper solution, please don't forgot to share this with your team members.