Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Spark's staticFileLocation method not found

Has anybody ever had a problem with IntelliJ not recognizing Spark's staticFileLocation method? I imported the method manually (because IntelliJ wasn't finding it by itself) and then followed the video just as Craig described it. Here is the relevant code I have:

import static spark.Spark.staticFileLocation;

public class Main {
    staticFileLocation("/public");
}

The import line is greyed out and IntelliJ says that the method is never used when I hover over the import line. IntelliJ also underlines the method call in a red, squiggly line saying that the method is an invalid method declaration.

Any ideas on why IntelliJ isn't recognizing this properly?

1 Answer

While you have a class you need be inside a method to run code like that. In this case you need a main() method to be the starting point of the program:

public class Main {
    public static void main(String[] args) {
        staticFileLocation("/public");
    }
}

Thanks for catching that dumb mistake...and for not downvoting it:).