I'm a Wicket beginner programming a simple forum. I have now implemented a PostgreSQL database to store the queries and also modified the contact page for this. But it no longer works and throws an error. I have checked the code several times but I absolutely do not know where the error is. I use NetBeans as IDE. Here is the stacktrace:
Root cause: java.lang.ClassNotFoundException: com.sample.database.CommentDao at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1420) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1228) at com.sample.contactpage.ContactPage.(ContactPage.java:28) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:175) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:67) at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:90) at org.apache.wicket.core.request.handler.PageProvider$Provision.getPage(PageProvider.java:369) at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:170) at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78) at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:231) at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:202) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:910) at org.apache.wicket.request.RequestHandlerExecutor.execute(RequestHandlerExecutor.java:63) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:294) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:255) at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:277) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:208) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:307) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:367) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:639) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:882) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1647) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:833)
ContactPage class:
public class ContactPage extends BasePage {
public ContactPage() {
Form form = new ContactForm("form");
add(form);
}
@Override
public void setTitleModelObject() {
titleModel.setObject(getString("title.contactPage"));
}
}
ContactForm class:
public class ContactForm extends Form {
private String email;
private String text;
public ContactForm(String id) {
super(id);
setDefaultModel(new CompoundPropertyModel(this));
add(new TextField("email"));
add(new TextArea("text"));
}
@Override
protected void onSubmit() {
Comment comment = new Comment();
comment.setCreatedTime(new Timestamp(new Date().getTime()));
comment.setEmail(email);
comment.setTextOfComment(text);
CommentDao dao = new CommentDaoImpl();
dao.saveComment(comment);
setResponsePage(HomePage.class);
}
}
CommentDao class:
public interface CommentDao {
public void saveComment(Comment comment);
public List<Comment> getAllComments();
}
I couldn't find anything similar. I will appreciate any help.
CodePudding user response:
The first line of the exception message tells you the root cause of the problem:
Root cause: java.lang.ClassNotFoundException:
com.sample.database.CommentDao
In other words, the class/interface com.sample.database.CommentDao
is not on the classpath. Perhaps you haven't compiled that class or you are running the server in a way that is not using your compiled code.