Search code examples
javafiledirectorynullpointerexceptionload

Can't load files because of NullPointerException


Good evening, I'm currently working on my assignment and I have been looking for hours finding this error. I tried catching the NPE which didn't work either. What am I missing?

The method's purpose is to load all files in the folder "templates" which have the suffixes ".txt" as objects from the class CuttingTemplate. The name's from the read templates are then set to the direction of the read file, so when the file template123.txt is in the folder "templates" the CuttingTemplate's name is set to "templates/template123.txt"; All loaded CuttingTemplates then are saved in this list:

protected LinkedList<CuttingTemplate> templates = new LinkedList<CuttingTemplate>();

Exceptions are caught (except the NPE which I couldn't figure out).

So here is the method:

Here is the stack trace:

enter image description here

I hope you can help me.


Solution

  • What OS are you on? Unix or Windows? Something tells me that that folder probably doesn't exist, since that path you provided is not what I'd expect from those two environments.

    In Windows, your path should probably look like this:

        C:/Users/username/Downloads/projectname/templates
    

    And in Unix it should look like this:

        /home/username/Downloads/projectname/templates