# ClassNotFoundException with "use"

james
255 2

I am sorry if this question seems a bit rediculous, but I'm still pretty new to ZK, and java in general.
I am consistently been unsuccessful with "use"ing or "apply"ing classes. I tried this little tutorial, as an example...
How to load tab contents on demand http://www.zkoss.org/smalltalks/netbeans2/netbeans2.dsp
And I get this as an exception "org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException: com.MyTabbox"
Likewise, this is the root cause "java.lang.ClassNotFoundException: com.MyTabbox"

When I try to use or apply a class the normal error is the 'ClassNotFoundException:' for what ever the name of the class is
Can anyone help me understand why I'm not able to use or apply classes?
I use tomcat 6, if that makes much of difference.
Thank you for any and all of your help

delete retag edit

## 6 Replies

RyanWu
533 2

can you provide you project config and test code ?
i think you didn't have right classpath or compile the source correctly .

james
255 2

Here is the code...

index.zul

<zk>
<window id="root">
<tabbox use="com.MyTabbox" id="tabbox" width="100%" >
<tabs>
<tab label="OnDemand 1"/>
<tab label="OnDemand 2"/>
</tabs>
<tabpanels>
<tabpanel>
</tabpanel>
<tabpanel id="second">
<include id="secondContent" src=""/>
</tabpanel>
<tabpanel id="third">
<include id="thirdContent" src=""/>
</tabpanel>
</tabpanels>
</tabbox>
</window>
</zk>


MyTabbox.java
package com;

import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Path;
import org.zkoss.zul.Include;
import org.zkoss.zul.Tabpanel;

public class MyTabbox extends org.zkoss.zul.Tabbox {

private int i=0;

public void onSelect() {

i++;

Tabpanel item = getSelectedPanel();

Desktop desktop = this.getDesktop();

desktop.setAttribute("time",i);

if(item != null && item.getId().equals("second")) {
Include inc = (Include)Path.getComponent("/root/secondContent");
inc.setSrc("secondTab.zul");
}
if(item != null && item.getId().equals("third")) {
Include inc = (Include)Path.getComponent("/root/thirdContent");
inc.invalidate();
inc.setSrc("thirdTab.zul");
}
}

}


web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>testing with the load on demand</display-name>
<listener>
<description>
Used to cleanup when a session is destroyed</description>
<display-name>
ZK Session Cleaner</display-name>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<description>
The servlet loads the DSP pages.</description>
<servlet-class>
org.zkoss.web.servlet.dsp.InterpreterServlet</servlet-class>
</servlet>
<servlet>
<description>
<servlet-class>
org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
</servlet>
<servlet>
<description>
The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>*.dsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>


mjablonski
1284 3 5
http://www.jease.org/

Hi James,

can you check, that there's a file called MyTabbox.class in tomcat/webapps/YourApplication/WEB-INF/classes/com? If not, you'll have to change your deployment to make it work.

Cheers, Maik

james
255 2

there was not.
I've tried a couple of different deployment options, non of which created that file. I created one... not sure what all was supposed to be in it, but i put the same code as MyTabbox.java.
I got this error...
java.lang.ClassFormatError: Incompatible magic value 1885430635 in class file com/MyTabbox

RyanWu
533 2

if you use eclipse
you should use Dynamic Web Project
or you have to copy the class to your classpath
(Default is WEB-INF/classes/ )

james
255 2

Hey... You know, I have been using the "Dynamic Web Project" and it hasn't worked. When I did it again, just to be sure and do as you said, I noticed this little option "Dynamic Web Module version" it defaults to 2.4 I changed it to 2.5 and it works now. I had previously just kept it as the default.
Thanks everyone for your time and help.
It works now

[hide preview]