I am novice at Java programming, and I'm trying to add a list of files to a crude little media player. Seemingly I've succeeded in achieving what I want with this:
public class MusicPlayerGUI
    implements ActionListener
{
    private static JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir"));
    private JList tracklist;
    private MusicPlayer player;
    private FileOrganizer organizer;
    private List<String> tracks;
    private JFrame frame;
public MusicPlayerGUI()
{
    player = new MusicPlayer();
    organizer = new FileOrganizer();
    tracks = organizer.listAllFiles();
    makeFrame();
}
//Some methods omitted
public void play()
{
    int fileToPlay = tracklist.getSelectedIndex();
    String filenameToPlay = organizer.getFile(fileToPlay);
    player.play(filenameToPlay);
}
public void setupList()
{
    tracks = organizer.listAllFiles();
    String[] fileList = listAllTracks(tracks);
    tracklist.setListData(fileList);
}
public String[] listAllTracks(List<String> tracks)
{
    int numTracks = tracks.size();
    String[] fileList = new String[numTracks];
    for(int i = 0; i < numTracks; i++) {
        String field = tracks.get(i).toString();
        fileList[i] = field;
    }
    return fileList;
}
But when I compile, even if it does compile, it gives me an error stating:
[pathname]/classname.java uses unchecked or unsafe operations. Recompile with Xlint:unchecked for details
And everything in my player works, except it won't play the files, so I'm thinking that there might be a connection between the compiler warning I get, and the fact that the files won't play. Can anyone spot what I'm getting wrong?
This happens when you assign a raw version of something to a version with a generic type parameter, like this:
List<String> list = new ArrayList(); // Note missing <String>
So my guess is that the listAllFiles method of FileOrganizer (whatever that is) returns List, not List<String>. Edit: Or user1631616 may have spotted it with your use of JList.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With