Java 图像图标不适用于JLabel

Java 图像图标不适用于JLabel,java,arrays,imageicon,Java,Arrays,Imageicon,我在我的项目中创建了一个文件夹,其中存储了19个图像,我将这些图像存储在一个数组中。我的JLabel循环浏览这些图像,目前只转到下一个图像,但不起作用 ImageIcon[] front_imagelist = new ImageIcon[19]; for(int i=0; i<front_imagelist.length; i++){ front_imagelist[i] = new ImageIcon(getClass().getResource( "/ben

我在我的项目中创建了一个文件夹,其中存储了19个图像,我将这些图像存储在一个数组中。我的JLabel循环浏览这些图像,目前只转到下一个图像,但不起作用

ImageIcon[] front_imagelist = new ImageIcon[19];

for(int i=0; i<front_imagelist.length; i++){
    front_imagelist[i] = new ImageIcon(getClass().getResource(
        "/ben/li/summative/frontimage/" + front_imagenames[i]));
}

if(count<front_imagenames.length){
    c1.setIcon(front_imagelist[count]);
    count++;
}

您确定正在调用setIcon并且from_imagelist[count]不为空吗?尝试使用SwingUtilities.invokeLater从事件线程中使用setIcon,看看是否有帮助。classpath下是否有resources文件夹。因为上面的代码将搜索资源文件夹中的图像,或者使用ImageIO加载ImagesOry的classpathTry,所以这个问题是在浪费您的时间。我用不正确的元素数声明了数组
//filename of frontcard images
String[] front_imagenames = {"2a.PNG","3a.PNG","4a.PNG","5a.PNG","6a.PNG","7a.PNG",
    "8a.PNG","9a.PNG","10a.PNG","11a.PNG","12a.PNG","13a.PNG",
    "14a.PNG","15a.PNG","16a.PNG","17a.PNG","18a.PNG","19a.PNG",};