Im trying to create a gradle jar which has a resource folder but when I build the project, the resource folder doesn't get included

I’d like to preface this by saying I know close to nothing about Gradle.

Anyway, my program uses png files as part of questions and answers, it’s a quiz program testing the user’s ability on the topic of the quiz. Anyway, when I run the program normally in Intellij it works fine. After building the jar file and running it, the pictures don’t show up. I assume this has to do with hard coding the file path like so: new ImageIcon("./src/main/resources/name.png");

I brought this up to a friend and he suggested that I use this line of code instead:
new ImageIcon(Objects.requireNonNull(getClass().getClassLoader().getResource(“name.png”)));
So I put this new code in my program and now I get a Null Pointer error. I don’t know why that’s happening, could be because the program can’t find the file, for some reason. But any and all help is appreciated. Thank you!

In which case? Running in IntelliJ, running the JAR file, both?

I get the null pointer error in both.