Search code examples
playframework-2.2

Play Framework [2.2.0-Java] Custom 404 page


Hi Everyone I'm using play 2.2.0 built with scala 2.10.2 (running java 1.7.0_45) I'm trying to make a custom Not Found Page but I don't have any success.

This is the code:

@Override
public Promise<SimpleResult> onHandlerNotFound(RequestHeader request) {
return Promise.<SimpleResult>pure(notFound(
views.html.myerrors.page404.render()
));
}

But I get this error

[error] path\app\Global.java:80: error: cannot find symbol
[error]                 return Promise.<SimpleResult>pure(notFound(
[error]                                                   ^
[error]   symbol:   method notFound(Html)
[error]   location: class Global
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code

Does somebody know the reason why and the solution?

Thank you in advance.


Solution

  • notFound is a static method of the play.mvc.Results class.

    It is probably not imported in your code. You can try to import it at the beginning of your file :

    import static play.mvc.Results.notFound;
    ...
    

    or import just the Results class if you don't want a static import :

    import play.mvc.Results;
    ...
    return Promise.<SimpleResult>pure(Results.notFound(
        views.html.myerrors.page404.render()));
    ...