IntelliJ - can't find resource, nullPointerException using getResource()
<p>Essentially, I'm using (or trying to use) Freemarker, which requires me to set up a folder for templates using</p>

<pre><code>cfg.setDirectoryForTemplateLoading(File dir);
</code></pre>

<p>I've created a folder <code>/htmltemplates</code> in <code>src/main/resources/htmltemplates</code>. The class I'm trying to access the resource from is in <code>src/main/java</code>.</p>

<p>However, when I try to use </p>

<pre><code>URL url = getClass().getResource("/htmltemplates");
File dir = new File(url.toString());
</code></pre>

<p>I get a nullPointerException. I've tried various combinations of ClassLoader, tried using a file instead of a directory (useless, he finds nothing), searched on StackOverflow for over an hour...
I had an almost identical setup on a previous occasion, everything worked swimmingly, but now - nothing. Attempts to work out what might be different have led to absolutely zilch.</p>

<p>I've been running the program through IntelliJ's build environment, also tried building a <code>.jar</code> artifact (which I'd been doing before, no problem) and then running it via console, nothing works. Any ideas why this is happening?</p>

<p>EDIT: This just keeps getting stranger. I've had other people at work try it out, we've both started new IntelliJ projects simultaneously, set them up identically, and they <em>can't replicate my problem</em>. What the hell?</p>