Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot use a method returning Unit as an Handler" getting this error in routes file - Play 2.0 Framework

I have these 2 methods in my contoller:

public static void index() {
   List<Tweet> tweets = Tweet.findLatest();
   render(Template("index.html").params(tweets).render());
}


public static void create(String tweet) {
   Tweet t = new Tweet();
   t.tweet = tweet;
   t.save();
   render(Template("index.html").params(t).render());
}

Now the routes is shouting at me saying "Cannot use a method returning Unit as an Handler". My route file has this default route defined in it:

GET / controllers.Application.index()

what could be the possible reason ?

like image 868
Raul Avatar asked Dec 21 '22 23:12

Raul


1 Answers

Raul, each action of the controller is expected to be static and to return Result

public static Result index() {
      List<Tweet> tweets = Tweet.findLatest();
      return ok(Template("index.html").params(tweets).render());
}
like image 116
biesior Avatar answered Mar 29 '23 23:03

biesior