2014-02-11 5 views
1

나는 놀이기구를위한 새로운 것이다.Play Framework에서 Null 포인터 예외를 해결하는 방법?

나는 두 가지 값을주고이 값을 다음 양식에 전달하는이 두 양식을 사용하고 있습니다.이 두 양식을이 다음 양식에 추가하고 싶습니다. 하지만 난 줄에 따라 null 포인터 excpetion있어

addition data=addform.get(); 

     return ok(
       sum_resul.render(data.First_No,data.Second_No)   //(sum was given form name) 
       ); 
     } 

어떻게이 문제를 해결할 수 있습니다. 여기

내 코드

경로

GET /       controllers.Application.index() 


GET /Sum_result     controllers.Application.sumresult() 


GET  /assets/*file    controllers.Assets.at(path="/public", file) 

Application.java

package controllers; 

import play.mvc.*; 
import play.data.*;          
import static play.data.Form.*;  
import play.data.validation.Constraints.*;   
import views.html.*; 

public class Application extends Controller { 

public static class addition 
{ 

    @Required @Min(1) @Max(100) 
    public Integer First_No; 

    @Required @Min(1) @Max(100) 
    public Integer Second_No; 

} 

public static Result index() { 
    return ok(index.render(Form.form(addition.class))); 
} 


public static Result sumresult() 
{ 

Form<addition> addform=form(addition.class).bindFromRequest(); 
    if(addform.hasErrors()) 
    { 
     return badRequest(index.render(addform)); 
    } 
    else 
    { 
     addition data=addform.get(); 

     return ok(
       sum_resul.render(data.First_No,data.Second_No)   
       ); 
     } 


} 



} 

index.scala

01 23,581,197,267,

sum_resul.scala

@(First_No: Int, Second_No: Int) 

@main("Here is the result:") { 

<h1> 
Sum of @First_No and @Second_No was (First_No+Second_No) 
</h1> 

<p class="buttons"> 
    <a href="@routes.Application.index">Back to the form</a> 
</p> 
} 

예외 같은

enter image description here

제발 도와주세요. 미리 감사드립니다.

답변

1

상당히 자명 한 것처럼 보입니다. data이 null이고 그 값을 검색하려고합니다. 그래서 왜 그것이 null인지 추적해야합니다.

+0

어떻게 그 값을 검색 할 수 있습니까? 제발 ... – selvam

0
if(data.size>0) 
    return ok(
       sum_resul.render(data.First_No,data.Second_No)   //(sum was given form name) 
       ); 
관련 문제