0

I am novice at java programming, and I'm trying to add a list of files to a crude, little mediaplayer. I'm using a JList to display the filename Strings, but want to store them in a DefaultListModel so that I can add and remove files. As far as I'm, I need to add a String for each file in my collection (which is stored in a different class), but whenever I try to compile I get the following error:

[pathname]/classname.java uses unchecked or unsafe operations. Recompile with Xlint:unchecked for details

Can someone please tell me what I'm doing wrong?

private void makeList()
{
    DefaultListModel listModel = new DefaultListModel();
    int collectionSize = tracklist.getCollectionSize();

    for(int i = 0; i < collectionSize; i++){
        String filename = tracklist.getFilename(i);
        listModel.addElement(filename);
    }
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
SorenRomer
  • 217
  • 1
  • 10

1 Answers1

2

you need to declare listModel like this

DefaultListModel <String> listModel = new DefaultListModel<>();

This enforce the compiler to check if you add a real string object into this collection whose elements must be the string type

sotondolphin
  • 223
  • 1
  • 10