我在netbeans有问题这个页面是工作100%idk今天我正在检查我的工作,因为我已经审查了这个错误来时,我想保存预订信息我不知道为什么:(
无法将java.lang.integer转换为java.lang.string
这是我的java代码,如果你能帮忙我会很感激的
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.validator.constraints.Length;
@ManagedBean(name="Bookingbean")
@RequestScoped
public class BookingTicket implements java.io.Serializable {
public SessionFactory sessionFactory;
public Transaction transaction;
public Session session;
public Configuration cfg;
private int tid;
private String movieName;
private String row;
private Integer noTicket;
private Double total;
private Integer card;
private Integer phone;
private Double price;
private Integer rownum;
public String mname;
public double movieprice;
public BookingTicket() {
cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
sessionFactory=cfg.buildSessionFactory();
session = sessionFactory.openSession();
}
public BookingTicket(int tid) {
this.tid = tid;
}
public BookingTicket(int tid, String movieName, String row, Integer noTicket, Double total, Integer card, Integer phone) {
this.tid = tid;
this.movieName = movieName;
this.row = row;
this.noTicket = noTicket;
this.total = total;
this.card = card;
this.phone = phone;
}
public int getTid() {
return this.tid;
}
public void setTid(int tid) {
this.tid = tid;
}
public String getMovieName() {
return this.movieName;
}
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public String getRow() {
return this.row;
}
public void setRow(String row) {
this.row = row;
}
public Integer getNoTicket() {
return this.noTicket;
}
public void setNoTicket(Integer noTicket) {
this.noTicket = noTicket;
}
public Double getTotal() {
return this.total;
}
public void setTotal(Double total) {
this.total = total;
}
public Integer getCard() {
return this.card;
}
public void setCard(Integer card) {
this.card = card;
}
public Integer getPhone() {
return this.phone;
}
public void setPhone(Integer phone) {
this.phone = phone;
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Transaction getTransaction() {
return transaction;
}
public void setTransaction(Transaction transaction) {
this.transaction = transaction;
}
public Session getSession() {
return session;
}
public void setSession(Session session) {
this.session = session;
}
public Configuration getCfg() {
return cfg;
}
public void setCfg(Configuration cfg) {
this.cfg = cfg;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Integer getRownum() {
return rownum;
}
public void setRownum(Integer rownum) {
this.rownum = rownum;
}
public String getMname() {
return mname;
}
public void setMname(String mname) {
this.mname = mname;
}
public String display()
{
mname=movieName;
return mname;
}
public double getMovieprice() {
return movieprice;
}
public void setMovieprice(double movieprice) {
this.movieprice = movieprice;
}
public List<BookingTicket> showAllRecordsticket()
{
//step 4
transaction = session.beginTransaction();
Query query = session.createQuery("from BookingTicket");
List<BookingTicket> ticket = query.list();
transaction.commit();
return ticket;
}
public double totalno()
{
if(movieName.equals("After"))
{ movieprice = 3.000;}
else if (movieName.equals("Black"))
{ movieprice = 4.000;}
else if (movieName.equals("The Greatest showman"))
{ movieprice = 3.000;}
else { movieprice = 3.000;}
// total=(price + rownum) * noTicket;
total = (rownum + movieprice) * noTicket;
return total;
}
public void saveTicket()
{
transaction = session.beginTransaction();
session.save(new BookingTicket(getTid(),getMovieName(),getRow(),getNoTicket(),getTotal(),getCard(),getPhone()));
transaction.commit();
}
idk问题在哪里?这就是为什么我写了几乎所有的java代码,因为它确实在工作:“(这是strack跟踪
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at javax.faces.validator.RegexValidator.validate(RegexValidator.java:163)
at javax.faces.component.UIInput.validateValue(UIInput.java:1248)
at javax.faces.component.UIInput.validate(UIInput.java:1037)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1334)
at javax.faces.component.UIInput.processValidators(UIInput.java:757)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1298)
at javax.faces.component.UIForm.processValidators(UIForm.java:269)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1298)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1298)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1332)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:77)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:201)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:670)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:745)
暂无答案!
目前还没有任何答案,快来回答吧!