Ive got problem with filechooser, with taking directory path into images viewer exactly. I want to get all images from the selected directory. Ive got NullPointerException in line
String[] imagesList = selectedDirectory.list();
Here's the code:
JFileChooser wybierz = new JFileChooser();
File selectedDirectory;
String path;
int pos = 0;
public String[] getImages() {
String[] imagesList = selectedDirectory.list();
return imagesList;
}
public void showImage(int index) {
String[] imagesList = getImages();
String imageName = imagesList[index];
ImageIcon icon = new ImageIcon(getClass().getResource(path));
Image image = icon.getImage().getScaledInstance(jLabel_Image.getWidth(), jLabel_Image.getHeight(), Image.SCALE_SMOOTH);
jLabel_Image.setIcon(new ImageIcon(image));
}
public void fileChooser() {
wybierz.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
wybierz.setAcceptAllFileFilterUsed(false);
wybierz.addChoosableFileFilter(new FileNameExtensionFilter("Image Files", "jpg", "png", "tif"));
int v = wybierz.showOpenDialog(null);
if (v == JFileChooser.APPROVE_OPTION) {
File selectedDirectory = wybierz.getSelectedFile();
showImage(pos);
}
}
what's the problem?