Wednesday, 15 January 2014

MVC SPRING - org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException -



MVC SPRING - org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException -

this question has reply here:

what null pointer exception, , how prepare it? 12 answers

i got httpstatus 500 nested exception , java.lang.nullpointerexception im making multicurrency converter used debug when here error starts currencypojo.setamount(bigdecimal.valueof(integer.parseint((request.getparameter("txtamount")))));

multicurrencycontroller.java

package com.multicurrency; import java.math.bigdecimal; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.springframework.web.servlet.modelandview; import org.springframework.web.servlet.mvc.abstractcontroller; public class multicurrencycontroller extends abstractcontroller{ private multicurrencypojo currencypojo; @override protected modelandview handlerequestinternal(httpservletrequest request, httpservletresponse response) throws exception { currencypojo.setamount(bigdecimal.valueof(integer.parseint((request.getparameter("txtamount"))))); currencypojo.setcurrency(request.getparameter("currency")); homecoming new modelandview ("home","currencyinfo",currencypojo); } public void multicurrencypojo(multicurrencypojo currencypojo){ this.currencypojo=currencypojo; } }

multicurrencypojo.java

package com.multicurrency; import java.math.bigdecimal; public class multicurrencypojo { private string currency; private bigdecimal amount; public string getcurrency() { homecoming currency; } public void setcurrency(string currency) { this.currency = currency; } public bigdecimal getamount() { homecoming amount; } public void setamount(bigdecimal amount) { this.amount = amount; } public static bigdecimal getexchangerate(string currency) { homecoming null; } }

it parameter txtamount not set on http request. in order have more clarity on error occurred, recommend splitting separate line rest of type conversion , explicitly checking it's set.

for example:

string txtamount = request.getparameter("txtamount"); if (txtamount == null) { throw new illegalargumentexception("expected http request parameter txtamount not present"); } currencypojo.setamount(bigdecimal.valueof(integer.parseint((txtamount));

(also, i'd question need bigdecimal in first place - particularly since you're converting integer, that's not subject of question.)

java spring spring-mvc servlets

No comments:

Post a Comment