As the title states I get the "java.lang.NullPointerException" in my constructor on the following code. I am aware that this means that i am "pointing" at something with value null but I can't see why. The file "mypictures" are located in C:\Users\jon\eclipse-workspace\Memory\src.
I am guessing that the for-loop meant to fill the array is not working but again, I really can't see why.
public class Memory extends JFrame implements ActionListener {
public Memory() {
File folder = new File("mypictures");
File[] pictures = folder.listFiles();
Card[] allCards = new Card[pictures.length];
for (int i = 0; i < pictures.length; i++) {
String path = pictures[i].getPath();
ImageIcon bild = new ImageIcon(path);
allCards[i] = new Card(bild);
}
public static void main(String[] args) {
new Memory();
}
Shouldn't this make an array filled with objects Card and not null? There is probably some novice mistake somewhere but I can't figure it out. I can post the Card code but I believe that the fault is here.
I'm grateful for any responses!