Adriano Valente Adriano Valente -4 years ago 161
Java Question

NullPointerException using getResource

I'm trying to create some application to recognize faces, following this tutorial. However, whenever I run the code below, I get this error: Exception in thread "main" java.lang.NullPointerException

class DetectFaceDemo {
public void run () {
CascadeClassifier faceDetector =
new CascadeClassifier(getClass()

Am I supposed to copy the xml file to some directory?


Answer Source

From your comment, I think you put your main/resources in the wrong directory (and you forgot the src part of the tree).

From the tutorial, you should have the following structure: src/main/java/<Java packages or classes>

You already have the src folder there. Create a main directory in src, and a resources directory in main. Put your XML file in the resources directory and you should be good to go.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download