Hi everyone,
I'm having a little problem I'm sure someone can help me with. I'm trying to read in 10 png images and save them in an ArrayList as BufferedImage objects (I think this is the right way to go about it but if not plaease say so).
Here is my code so far:
package imageloader;
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
import java.util.ArrayList;
public class Interface
{
/* Fields */
private ArrayList<String> fileList = new ArrayList<String>();
private ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>();
/* Constructor */
public Interface()
{
buildFileList();
loadImages();
}
/**
* Method to populate the fileList array.
*/
private void buildFileList()
{
fileList.add( "./images/image1.png" );
fileList.add( "./images/image2.png" );
fileList.add( "./images/image3.png" );
fileList.add( "./images/image4.png" );
fileList.add( "./images/image5.png" );
fileList.add( "./images/image6.png" );
fileList.add( "./images/image7.png" );
fileList.add( "./images/image8.png" );
fileList.add( "./images/image9.png" );
fileList.add( "./images/image10.png" );
}
/**
* Method to load images from file and store internally.
*/
private void loadImages()
{
BufferedImage temp = null;
try
{
for( String item : fileList )
{
temp = ImageIO.read( new File( item ) );
imageList.add( temp );
}
}
catch( IOException e )
{
System.err.println( e.getMessage() );
}
}
}
I'm trying to read all files in and store them all in an ArrayList as BufferedImage objects, but I'm getting a "Can't read input file!" error message and I'm not sure what I'm doing wrong here. The paths are all okay. Any suggestions?
Thanks!