I'm trying to create a small program that read images from a file. I'm getting at least 2 errors pointed on the line 25 and 41, would you help me to fix these errors please? Thank You
public RoadSafetyAuthority() {
initComponents();
//dispaly fisrt image
showImage(pos); // Line 25
}
int pos = 0;
public String[] getImages() {
File file = new File(getClass().getResource("/Images/Information Signs").getFile());
String[] imagesList = file.list();
return imagesList;
}
//display the image by index
public final void showImage(int index) {
String[] imagesList = getImages();
String imageName = imagesList[index]; // Line 41
ImageIcon icon = new
ImageIcon(getClass().getResource("/Images/Information Signs" + imageName));
Image image =
icon.getImage().getScaledInstance(jImageLabel.getWidth(),jImageLabel.getHeight(), Image.SCALE_SMOOTH);
}
private void jBtnNextActionPerformed(java.awt.event.ActionEvent evt) {
pos = pos - 1;
if(pos >= getImages().length) {
pos = getImages().length - 1;
}
showImage(pos);
}
private void jBtnPreviousActionPerformed(java.awt.event.ActionEvent evt) {
pos = pos -1;
if(pos < 0) {
pos = 0;
}
showImage(pos);
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at assignment1.RoadSafetyAuthority.showImage(RoadSafetyAuthority.java:41)
at assignment1.RoadSafetyAuthority.<init>(RoadSafetyAuthority.java:25)
at assignment1.RoadSafetyAuthority$3.run(RoadSafetyAuthority.java:157)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)