When I am giving absolute path of image means from my project scr
directory it loads the image but when I am trying to load image from specified path or relative path then it shows null error, it doesn't read image.
i have get path using JFilechooser
directory specifically, it only display .jpg
image and give list of files to File type and stored one by one image in string variable and then want to load image using that variable.
My code:
final String fpath;
final File dir = new File("");
final JFileChooser file;
file = new JFileChooser();
file.setCurrentDirectory(dir);
file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
file.showOpenDialog(contentPane);
final File[] lofFile = file.getCurrentDirectory().listFiles();
for (int i = 0; i < a; i++) {
if (lofFile[i].toString().substring(lofFile[i].toString().lastIndexOf(".") + 1).equals("jpg")) {
az = lofFile[i].toString();
}
}
private BufferedImage bg;
bg = ImageIO.read(getClass().getResource(az));
Throws this exception:
java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source)
Any help please?