when I put this line into my application I'm no longer able to start my application and I don't know why.
I'm using Play 2.5.
public class HomeController extends Controller {
Form<User> userForm = Form.form(User.class); // get error if I put this line in
public Hashtable<Integer, String> hmap = new Hashtable<>();
If I generate the form in the controller I get the error.
Error I get:
ProvisionException: Unable to provision, see the following errors:
1) Error injecting constructor, java.lang.RuntimeException: There is no started application
at controllers.HomeController.<init>(HomeController.java:15)
while locating controllers.HomeController
for parameter 1 at router.Routes.<init>(Routes.scala:32)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:201)
while locating play.api.http.JavaCompatibleHttpRequestHandler
while locating play.api.http.HttpRequestHandler
for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
at play.api.DefaultApplication.class(Application.scala:221)
while locating play.api.DefaultApplication
while locating play.api.Application
1 error
What causes this? Any ideas?
Edit:
HomeController.java
package controllers;
import play.mvc.*;
import java.util.*;
import models.User;
import play.data.Form;
public class HomeController extends Controller {
Form<User> filledForm = Form.form(User.class);
public Hashtable<Integer, String> hmap = new Hashtable<>();
public Result index() {
return ok(views.html.index.render());
}
public Result saveData() {
User user = filledForm.bindFromRequest().get();
if (filledForm.hasErrors()) {
// process
} else {
// contactForm.get().firstName should be filled with the correct data
System.out.println("Nothing to show here.");
}
System.out.println(user.name);
System.out.println(user.tableNr);
return ok(views.html.index.render());
}