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
package softmint.com;
import java.sql.Connection;
//import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
//import java.text.SimpleDateFormat;
import javax.xml.ws.WebServiceRef;
import kcb.com.Merchantcustomerupdate_Service;
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() {
kcb.com.Merchantcustomerupdate port = service.getMerchantcustomerupdatePort();
port.update(balance, maccount, cardno);
// return port.update(balance, maccount, cardno);
}
public void insertt(){
{
try
{
Class.forName("com.mysql.jdbc.Driver");
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(6,lname);
ps.setString(8, bname);
ps.setInt(1,amount);
//ps.setDate(2, tdate);
ps.setString(3, cardtype);
ps.setLong(4, amount);
ps.setString(5,cemail);
if(tdate != null)
{
String date = fmt.format(tdate);
Object obj = date;
if(obj == null)
{
ps.setDate(11, null);
}
else
{
java.sql.Date dt = java.sql.Date.valueOf(new String(date));
ps.setDate(2, dt);
}
}
ps.executeUpdate();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
public void all(){
insertt();
update();
}
}
payment.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<title>payment Details</title>
</head>
<ui:include src="header.xhtml"/>
<body>
<div id="part" >
<f:view>
<h:form id="registerForm">
<table>
<tr>
<td><h:outputText value="payment option"/></td>
<td><h:outputLabel id="cardss" value="#{bankconnect.cardtype}"
/></td>
<td></td>
</tr>
<tr>
<td><h:outputText value="Amount :"/></td>
<td><h:inputText id="balance" value="#{bankconnect.balance}" /></td>
<td></td>
</tr></table>
<h5>Enter your card details to pay</h5>
<table>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<td><h:outputText value="expiry date:"/></td>
<td><h:inputText id="date" value="#{bankconnect.tdate}" > <f:convertDateTime pattern="yyyy-MM-dd"/></h:inputText>
</td>
<td><h:message for="Date" style="color:red"/></td>
</tr>
<tr>
<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>
</tr>
</table><br></br>
<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>
</h:form>
</f:view>
</div>
</body>
<ui:include src="footer.xhtml"/>
</html>
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
STACK TRACE
javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at softmint.com.Bankconnect.update(Bankconnect.java:224)
at softmint.com.Bankconnect.all(Bankconnect.java:283)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:779)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:528)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257)
at com.sun.el.parser.AstValue.invoke(AstValue.java:248)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 32 more