Exception in thread "main" java.lang.NoClassDefFoundError???

P

Piotre Ugrumov

I have downloaded this file: DomEcho1.java. I can compile this files,without
errors, with netbeans (I have imported the apis for this files in netbeans,
this file is an examples for XML-DOM). When I try to start this program,
this is the result:

C:\JAVA>java DomEcho1
Exception in thread "main" java.lang.NoClassDefFoundError: DomEcho1

How can I launch thsi example program?
Thanks.


//DomEcho1.java
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import java.io.File;
import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.DOMException;

public class DomEcho01{
// Global value so it can be ref'd by the tree-adapter
static Document document;

public static void main(String argv[])
{
if (argv.length != 1) {
System.err.println("Usage: java DomEcho filename");
System.exit(1);
}

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
//factory.setValidating(true);
//factory.setNamespaceAware(true);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse( new File(argv[0]) );

} catch (SAXException sxe) {
// Error generated during parsing)
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();

} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();

} catch (IOException ioe) {
// I/O error
ioe.printStackTrace();
}
} // main

}
 
C

Christophe Vanfleteren

Piotre said:
I have downloaded this file: DomEcho1.java. I can compile this
files,without errors, with netbeans (I have imported the apis for this
files in netbeans, this file is an examples for XML-DOM). When I try to
start this program, this is the result:

C:\JAVA>java DomEcho1
Exception in thread "main" java.lang.NoClassDefFoundError: DomEcho1

How can I launch thsi example program?
Thanks.
<snip code>

Try java -cp . DomEcho1

Then read the entry for NoClassDefFoundError at
http://mindprod.com/jgloss/errormessages.html
 
J

Joona I Palaste

Piotre Ugrumov said:
I have downloaded this file: DomEcho1.java. I can compile this files,without
errors, with netbeans (I have imported the apis for this files in netbeans,
this file is an examples for XML-DOM). When I try to start this program,
this is the result:
C:\JAVA>java DomEcho1
Exception in thread "main" java.lang.NoClassDefFoundError: DomEcho1
How can I launch thsi example program?
Thanks.

public class DomEcho01{
^^^^^^^^^

You'll want to check the class file name. Hint: "1" and "01" are not the
same thing!
 
M

Mohan Akula

Hello Piotre,

Solution to Exception in thread "main" java.lang.NoClassDefFoundError
I tried this on unix. It works beautifully.

$ ls -al test1.*
-rw-r--r-- 1 mohan users 415 Jan 28 11:58 test1.class
-rwxr-xr-x 1 mohan users 479 Jan 28 11:58 test1.java*
$ javac test1.java
$ java -classpath "/home/dir1/dir2/dir3/dir4" test1
hello World

Note that the classpath is the total path starting with the drive name
if using Windows. Hope that helps.

Regards,
Mohan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top