tags:

views:

28

answers:

2

Hi,

i wrote java code in beanshell but it throws java.lang.NoClassDefFoundError by defining DefaultHandler. I have already imported it, i don't understand why is this exception thrown. My Code looks like here:

import org.xml.sax.helpers.DefaultHandler;
try {
        XMLReader xr = XMLReaderFactory.createXMLReader();

        **DefaultHandler handler = new DefaultHandler() {
            variables
            .........
            methods(){
                   ..................
            }

        };**

        InputSource file = new InputSource(new StringReader(stringResult));
        xr.setContentHandler(handler);
        xr.parse(file);

} catch (Ex e) {
    .........
}

Thanks

+1  A: 

I have already imported it, i don't understand why is this exception thrown.

Importing it and having it in your CLASSPATH are two very different things. You might have had it in CLASSPATH when you compiled, but if it's not there at runtime you'll have an issue.

duffymo
but this is a java api class. what do i have to add to classpath?
bilal
I didn't think it is part of JDK. (Don't see a package referring to it in JDK 6 javadocs; perhaps I missed it.) You can download JAR from http://www.beanshell.org/ and add it to your CLASSPATH.
duffymo
A: 

Set the Class path correctly while you execute the binaries.

Setting the Class path

Chathuranga Chandrasekara