Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java lang null pointer exception in jsf and webservices  RSS feed

john kikuvi
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a j sf application that is using web-services to communicate to another application and pass some parameters to it.The application has three methods one to call the webservice,another to insert some values into a database and the third method to call the two methods when i click a button in a form.
The methods a are
  • update() this is for calling a webservice and passing parameters to it.
    insertt() to in sert to a database.
    all() to call the above two.

  • when i call upadate and insertt in all method am getting an error java lang null pointer exception but when i call just one of the methods it executes successfully.
    This is my code

    import java.sql.Connection;
    //import java.sql.Date;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    //import java.text.SimpleDateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    * @author kikuvi
    public class Bankconnect {
    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/KCB/merchantcustomerupdate.wsdl")
    private Merchantcustomerupdate_Service service;
    String bname;//merchant bussiness name
    String cardtype;//customer card btype
    String cemail;// customer email
    String itemtype;//donations/electricity/water etc;
    String rUrl;//url for successful transaction
    String fUrl;
    String cUrl;//url for cancelled transaction
    Long Tid;//transaction id
    int tamount;//transaction total amount in kenya shillings
    int tamount2;//transaction total amount in US dollars

    int tamount3;//shipping amount
    Date tdate;// transaction date
    Date eDate;//card expiry date
    long cardno;//customer card number
    long maccount;//merchant account number
    int cvv;// customer card verification code;
    public String lname;
    public String fname;
    int amount;

    public Merchantcustomerupdate_Service getService() {
    return service;

    public void setService(Merchantcustomerupdate_Service service) {
    this.service = service;

    public int getAmount() {
    return amount;

    public void setAmount(int amount) {
    this.amount = amount;

    public String getLname() {
    return lname;

    public void setLname(String lname) {
    this.lname = lname;

    public String getFname() {
    return fname;

    public void setFname(String fname) {
    this.fname = fname;

    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    public String getBname() {
    return bname;

    public void setBname(String bname) {
    this.bname = bname;

    public String getCardtype() {
    return cardtype;

    public void setCardtype(String cardtype) {
    this.cardtype = cardtype;

    public String getCemail() {
    return cemail;

    public void setCemail(String cemail) {
    this.cemail = cemail;

    public Long getTid() {
    return Tid;

    public void setTid(Long Tid) {
    this.Tid = Tid;

    public int getTamount() {
    return tamount;

    public void setTamount(int tamount) {
    this.tamount = tamount;

    public Date getTdate() {
    return tdate;

    public void setTdate(Date tdate) {
    this.tdate = tdate;

    int balance=0;

    public int getBalance() {
    return balance;

    public void setBalance(int balance) {
    this.balance = balance;

    public long getMaccount() {
    return maccount;

    public void setMaccount(long maccount) {
    this.maccount = maccount;

    public long getCardno() {
    return cardno;

    public void setCardno(long cardno) {
    this.cardno = cardno;

    public String getItemtype() {
    return itemtype;

    public void setItemtype(String itemtype) {
    this.itemtype = itemtype;

    public String getrUrl() {
    return rUrl;

    public void setrUrl(String rUrl) {
    this.rUrl = rUrl;

    public String getfUrl() {
    return fUrl;

    public void setfUrl(String fUrl) {
    this.fUrl = fUrl;

    public String getcUrl() {
    return cUrl;

    public void setcUrl(String cUrl) {
    this.cUrl = cUrl;

    public int getTamount2() {
    return tamount2;

    public void setTamount2(int tamount2) {
    this.tamount2 = tamount2;

    public int getTamount3() {
    return tamount3;

    public void setTamount3(int tamount3) {
    this.tamount3 = tamount3;

    public Date geteDate() {
    return eDate;

    public void seteDate(Date eDate) {
    this.eDate = eDate;

    public int getCvv() {
    return cvv;

    public void setCvv(int cvv) {
    this.cvv = cvv;

    PreparedStatement ps ;
    Connection con ;

    public void update() { port = service.getMerchantcustomerupdatePort();
    port.update(balance, maccount, cardno);
    // return port.update(balance, maccount, cardno);


    public void insertt(){
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/easypay", "root", "");
    String sql = "INSERT INTO transactions (tamount,tdate,cardtype,T_ID,cemail,LastName,FirstName,Btype) VALUES(?,?,?,?,?,?,?,?)";
    ps= con.prepareStatement(sql);
    ps.setString(7, fname);
    ps.setString(8, bname);
    //ps.setDate(2, tdate);
    ps.setString(3, cardtype);
    ps.setLong(4, amount);

    if(tdate != null)
    String date = fmt.format(tdate);
    Object obj = date;
    if(obj == null)
    ps.setDate(11, null);
    java.sql.Date dt = java.sql.Date.valueOf(new String(date));
    ps.setDate(2, dt);


    catch(Exception e)




    public void all(){



    <html xmlns=""
    <title>payment Details</title>
    <ui:include src="header.xhtml"/>

    <div id="part" >

    <h:form id="registerForm">
    <td><h:outputText value="payment option"/></td>
    <td><h:outputLabel id="cardss" value="#{bankconnect.cardtype}"
    <td><h:outputText value="Amount :"/></td>
    <td><h:inputText id="balance" value="#{bankconnect.balance}" /></td>
    <h5>Enter your card details to pay</h5>
    <td><h:outputText value="card number"/></td>
    <td><h:inputText id="cardkk" value="#{bankconnect.cardno}" required="true"
    requiredMessage="card field should be filled"/></td>
    <td><h:message for="name" style="color:red"/></td>
    <td><h:outputText value="CVV :"/></td>
    <td><h:inputText id="cvv" value="#{bankconnect.cvv}" required="true"
    requiredMessage="CVV field should be filled"/></td>
    <td><h:message for="CVV" style="color:red"/></td>
    <td><h:outputText value="expiry date:"/></td>
    <td><h:inputText id="date" value="#{bankconnect.tdate}" > <f:convertDateTime pattern="yyyy-MM-dd"/></h:inputText>

    <td><h:message for="Date" style="color:red"/></td>
    <td><h:outputText value="merchant account:"/></td>
    <td><h:inputText id="account" value="#{bankconnect.maccount}" required="true"
    requiredMessage="Date field should be filled"/></td>
    <td><h:message for="Date" style="color:red"/></td>


    <h:commandButton action="#{bankconnect.all()}" value="submitpayment"></h:commandButton>
    <h:commandButton action="submit" value="Back to payment option"></h:commandButton>
    <h:commandButton action="submit" value="cancel process"></h:commandButton>


    <ui:include src="footer.xhtml"/>

    when i include only one method in all() method its doing fine but when include the two am getting an error java lang null pointer exception

    javax.faces.el.EvaluationException: java.lang.NullPointerException
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(
    at com.sun.faces.application.ActionListenerImpl.processAction(
    at javax.faces.component.UICommand.broadcast(
    at javax.faces.component.UIViewRoot.broadcastEvents(
    at javax.faces.component.UIViewRoot.processApplication(
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(
    at com.sun.faces.lifecycle.Phase.doPhase(
    at com.sun.faces.lifecycle.LifecycleImpl.execute(
    at javax.faces.webapp.FacesServlet.service(
    at org.apache.catalina.core.StandardWrapper.service(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.core.StandardPipeline.doInvoke(
    at org.apache.catalina.core.StandardPipeline.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.doService(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(
    at com.sun.grizzly.http.ProcessorTask.doProcess(
    at com.sun.grizzly.http.ProcessorTask.process(
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(
    at com.sun.grizzly.DefaultProtocolChain.execute(
    at com.sun.grizzly.DefaultProtocolChain.execute(
    at com.sun.grizzly.http.HttpProtocolChain.execute(
    at com.sun.grizzly.ProtocolChainContextTask.doCall(
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(
    at com.sun.grizzly.util.AbstractThreadPool$
    Caused by: java.lang.NullPointerException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at javax.el.BeanELResolver.invokeMethod(
    at javax.el.BeanELResolver.invoke(
    at javax.el.CompositeELResolver.invoke(
    at com.sun.el.parser.AstValue.invoke(
    at com.sun.el.MethodExpressionImpl.invoke(
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(
    at org.jboss.weld.el.WeldMethodExpression.invoke(
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(
    ... 32 more
    Tim Holloway
    Posts: 18662
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Two things you can do to make it easier for us to understand your problem:

    1. Remove all non-essential code from your samples. If we have to figure out what's important to the problem and what isn't, often we won't bother. Nobody gets paid to do this, after all, so if it doesn't easily all fit on the computer screen, your audience gets a lot smaller.

    2. Use the "Code" button in our message editor to wrap code tags around your sample Java code and XML. That makes it a lot easier to read.

    You didn't mention which line in your update method the NullPointerException is being thrown from. Either the "service" property of your bean is null, or the "port" property is, but that's as good as I can guess.

    You don't have "service" defined as a ManagedProperty, so unless you have initialized it manually, it would be null. If you did initialize it, I couldn't tell from your sample because of item 1, above.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!