2016-08-14 2 views
0

Я новичок в PlayFramework, и я следую видеокурсу на Udemy. Однако их версия из Play 2.3.9, и я пытаюсь сделать это с версией 2.5.4;NullPointerException при попытке сохранить мою форму

Когда я пытаюсь сохранить свою форму, он дает мне следующую ошибку:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: java.lang.NullPointerException]] 
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280) 
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206) 
    at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160) 
    at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188) 
    at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98) 
    at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100) 
    at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99) 
    at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344) 
    at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343) 
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) 
Caused by: java.util.concurrent.CompletionException: java.lang.NullPointerException 
    at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292) 
    at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308) 
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593) 
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577) 
    at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) 
    at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977) 
    at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:21) 
    at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:18) 
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) 
    at scala.concurrent.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:63) 
Caused by: java.lang.NullPointerException: null 
    at com.avaje.ebean.Model.save(Model.java:208) 
    at controllers.Services.save(Services.java:28) 
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$6$$anonfun$apply$6.apply(Routes.scala:227) 
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$6$$anonfun$apply$6.apply(Routes.scala:227) 
    at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:157) 
    at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:156) 
    at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$14$$anon$3$$anon$1.invocation(HandlerInvoker.scala:136) 
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:73) 
    at play.http.HttpRequestHandler$1.call(HttpRequestHandler.java:54) 
    at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:108) 

Моя форма:

@(serviceForm : Form[Service]) 
@import helper._ 


@main("Service info"){ 
    <h1>Service Information</h1> 
    @helper.form(action = routes.Services.save()){ 
    <fieldset> 
     <legend>Service</legend> 
     @helper.inputText(serviceForm.field("code"), '_label -> "Code") 
     @helper.inputText(serviceForm.field("description"), '_label -> "Description") 
    </fieldset> 
    <input type="submit" value="Save"/> 
    } 
} 

Моя модель:

@Entity 
public class Service extends Model { 
    @Id 
    public String code; 
    public String description; 

    public String getCode() { 
     return code; 
    } 

    public void setCode(String code) { 
     this.code = code; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 
} 

Мой контроллер:

public class Services extends Controller { 

    @Inject FormFactory formFactory; 

    public Result list(){ 
     return TODO; 
    } 

    public Result addService(){ 
     Form<Service> serviceForm = formFactory.form(Service.class); 
     return ok(info.render(serviceForm)); 
    } 

    public Result save(){ 
     Form<Service> serviceForm = formFactory.form(Service.class); 
     Service service = serviceForm.bindFromRequest().get(); 
     service.save(); 

     return redirect(routes.Services.addService()); 
    } 
} 

Я действительно не знаю, куда идти отсюда. И в Google не так много сообщений об этом. Любая помощь будет замечательной!

EDIT

enter image description here enter image description here

+0

Использует ли 'serviceForm.bindFromRequest(). Get();' возвращает ненулевое значение? – c0der

ответ

0

Для тех, кто может иметь один и те же, или родственные, проблемы. Please check my new post here. В основном, моя проблема заключалась в версии плагина Ebean.

Также вы можете увидеть мои изменения в моем репозитории here.

0

ли эта помощь?

Issue with bindFromRequest in Play! Framework 2.3

I have been struggling with exactly the same problem: bindFromRequest returned nulls for "name" field. I did exactly the same what a guy in this Play for Java introduction video did: youtube.com/watch?v=bLrmnjPQsZc . But still no luck. I've been working on Windows 7 with JDK 1.8. IDE: Eclipse 4.4.0. And I run activator through cygwin.

This is what solved the problem for me:

In Eclipse: Project -> Build Automatically - > turn off In cygwin: ./activator clean; ./activator compile; ./activator run; After this, bindFromRequest binds name correctly and puts it into the database.

+0

Нет, все та же ошибка. Спасибо за отзыв в любом случае! :) –