I'm getting the following error on Play 2.1.3: [RuntimeException: Cannot instantiate class controllers.Application$User. It must have a default constructor]
Here's my Application.java file...I can't tell what I'm doing wrong! This occurs when I make a POST request to /login.
package controllers;
import play.mvc.*;
import play.data.*;
import views.html.*;
public class Application extends Controller {
private static boolean loggedin = false;
private static User currentUser;
private static Form<User> LoginForm = Form.form(User.class);
public static Result index() {
String message, title;
if(!loggedin)
{
title = "Login";
message = "Please log in.";
}
else
{
title = "Welcome";
message = "You are logged in!";
}
return ok(index.render(title, message, loggedin));
}
public static Result login() {
currentUser = LoginForm.bindFromRequest().get();
if(currentUser.getUsername().equals("test") && currentUser.getPassword().equals("password")) {
loggedin = true;
return redirect(routes.Application.index());
}
else {
String title = "Login";
String message = "An error occurred. Please try logging in again.";
return ok(index.render(title, message, loggedin));
}
}
static class User {
private String username;
private String password;
public User() {
this.username = "";
this.password = "";
}
public String getUsername() {
return this.username;
}
public String getPassword() {
return this.password;
}
}
}