Java JSF-从datatable中删除时出现空指针异常
我正在用eclipse开发一个jsf应用程序,其中我有一个从数据库成功加载的datatable,我在托管bean中添加了一个remove按钮和一个delete方法,但问题是当我单击该按钮时,它会给出一个空指针异常。 我怎样才能解决这个问题 托管BeanJava JSF-从datatable中删除时出现空指针异常,java,jsf,jakarta-ee,nullpointerexception,Java,Jsf,Jakarta Ee,Nullpointerexception,我正在用eclipse开发一个jsf应用程序,其中我有一个从数据库成功加载的datatable,我在托管bean中添加了一个remove按钮和一个delete方法,但问题是当我单击该按钮时,它会给出一个空指针异常。 我怎样才能解决这个问题 托管Bean @ManagedBean @SessionScoped public class MonitorProjectsBean { @EJB private ProjectServiceLocal projectServiceLocal; priva
@ManagedBean
@SessionScoped
public class MonitorProjectsBean {
@EJB
private ProjectServiceLocal projectServiceLocal;
private List<ProjectMonitoring> listpm=new ArrayList<ProjectMonitoring>();
private ProjectMonitoring selectedPm;
private ProjectMonitoringServiceLocal projectMonitoringServiceLocal;
public String delete(ProjectMonitoring pm){
System.out.println("delte method");
projectMonitoringServiceLocal.delete(pm);
return "/pages/admin/MonitorProjects?faces-redirect=true";}
@PostConstruct
public void init() {
listpm=projectServiceLocal.findAllProjectMonitoring();
selectedPm =new ProjectMonitoring();
//System.out.println(listpm.get(0).getDescription());
}
public String addPM()
{
projectMonitoringServiceLocal.save(selectedPm);
return "/pages/admin/MonitorProjects?faces-redirect=true";
}
public ProjectServiceLocal getProjectServiceLocal() {
return projectServiceLocal;
}
public void setProjectServiceLocal(ProjectServiceLocal projectServiceLocal) {
this.projectServiceLocal = projectServiceLocal;
}
public List<ProjectMonitoring> getListpm() {
return listpm;
}
public void setListpm(List<ProjectMonitoring> listpm) {
this.listpm = listpm;
}
public ProjectMonitoring getSelectedPm() {
return selectedPm;
}
public void setSelectedPm(ProjectMonitoring selectedPm) {
this.selectedPm = selectedPm;
}
public ProjectMonitoringServiceLocal getProjectMonitoringServiceLocal() {
return projectMonitoringServiceLocal;
}
public void setProjectMonitoringServiceLocal(ProjectMonitoringServiceLocal projectMonitoringServiceLocal) {
this.projectMonitoringServiceLocal = projectMonitoringServiceLocal;}}
您的
ProjectMonitoringServiceLocal
是EJB吗?调试并检查调用delete时此projectMonitoringServiceLocal
是否为空
看起来您遗漏了一个批注:
@EJB private ProjectMonitoringServiceLocal projectMonitoringServiceLocal;
这就是整个堆栈跟踪?我用完整的堆栈跟踪进行了编辑
Servlet Path:
/pages/admin/MonitorProjects.jsf
Path Info:
null
Query String:
null
Stack Trace
javax.servlet.ServletException: java.lang.NullPointerException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:667)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
@EJB private ProjectMonitoringServiceLocal projectMonitoringServiceLocal;