我想知道以下代码为什么不起作用。我尝试根据文件的元数据值创建两个ArrayList<String>
。在这种情况下,.mp3
个文件。
private Stage stage;
private List<File> filelist;
private Map<String, Object> map;
private ArrayList<String> artist;
private ArrayList<String> title;
public void open(){
FileChooser chooser = new FileChooser();
filelist = chooser.showOpenMultipleDialog(stage);
for (int i = 0; i <= filelist.size(); i++){
try {
Media media = new Media(filelist.get(i).toURI().toURL().toString());
map = media.getMetadata();
title.add(map.get("title").toString());
artist.add(map.get("artist").toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
public void test(){
for (int i = 0; i <= filelist.size(); i++){
System.out.println(filelist.get(i).getName());
System.out.println(title.get(i));
System.out.println(artist.get(i));
}
}
当我尝试打印艺术家和标题中的值时,会出现错误