Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

ClassDefNotFound error with xpath.evaluate...

Thread view: 
drakaan@gmail.com - 10 Apr 2007 22:17 GMT
Well, I managed to get stuck just before I actually see any results
from a foray into using xpath with java.

I have some code (fairly straightforward):

56: String expression = "/systems/system";
57: InputSource inputSource = new InputSource("/folder/" + fileName);
58: XPath xpath = XPathFactory.newInstance().newXPath();
59: NodeList nodes = (NodeList) xpath.evaluate(expression,
inputSource, XPathConstants.NODESET);

That throws the following errors when run within the Eclipse IDE,
regardless of which folder/filename or expression I throw at it:

Exception in thread "main" java.lang.NoClassDefFoundError:
gnu.xml.pipeline.DomConsumer
  at gnu.xml.pipeline.DomConsumer$Handler.<init>(libgcj.so.7rh)
  at gnu.xml.pipeline.DomConsumer.<init>(libgcj.so.7rh)
  at gnu.xml.dom.Consumer.<init>(libgcj.so.7rh)
  at gnu.xml.dom.JAXPFactory$JAXPBuilder.<init>(libgcj.so.7rh)
  at gnu.xml.dom.JAXPFactory.newDocumentBuilder(libgcj.so.7rh)
  at gnu.xml.xpath.Expr.evaluate(libgcj.so.7rh)
  at gnu.xml.xpath.XPathImpl.evaluate(libgcj.so.7rh)
  at updateParser.SysmonParser.parseXml(Parser.java:59)

I have the following imports:

import java.util.Date;
import javax.xml.xpath.*;
import org.xml.sax.*;
import java.io.File;
import java.io.IOException;
import org.w3c.dom.*;
import org.jrobin.core.*;

My xml looks like:

<?xml version="1.0"?>

<systems>

    <system id="12345678" address="xx.xx.xx.xx" osclass="windows"
uptime="1D 2H 51M">
       </system>
</systems>

I'm very new to java, but not to xml data manipulation.  The java
examples that I found seemed pretty straightforward (although they
often failed to mention what imports are required).  My first thought
is still that I'm missing a library reference or something (I'm on
Fedora Core 6, Eclipse 3.2.0, and my workspace default is the
java-1.4.2-gcj-1.4.2.0 JRE).

Any insight as to how I might narrow down the cause of that
classDefNotFound error?  It's driving me absolutely nuts.

Help.  Please.
Joshua Cranmer - 10 Apr 2007 22:22 GMT
> Exception in thread "main" java.lang.NoClassDefFoundError:
> gnu.xml.pipeline.DomConsumer
[quoted text clipped - 6 lines]
>    at gnu.xml.xpath.XPathImpl.evaluate(libgcj.so.7rh)
>    at updateParser.SysmonParser.parseXml(Parser.java:59)

A NoClassDefFoundError signifies that the VM cannot find the class file;
my recommendation would be to check the classpath.
Bozo Bits - 11 Apr 2007 00:09 GMT
> drak...@gmail.com wrote:
> > Exception in thread "main" java.lang.NoClassDefFoundError:
> > gnu.xml.pipeline.DomConsumer
> >
> A NoClassDefFoundError signifies that the VM cannot find the class file;
> my recommendation would be to check the classpath.

Given that you are using GCJ, have you tried building and running
using a current Sun JDK? The NoClassDefFoundError in this context is
clearly a runtime error and so checking the classpath is probably the
first thing to do. If you had a bad import you should get a compile
time error instead.

bozo bits
drakaan@gmail.com - 11 Apr 2007 14:31 GMT
> > drak...@gmail.com wrote:
> > > Exception in thread "main" java.lang.NoClassDefFoundError:
[quoted text clipped - 10 lines]
>
> bozo bits

...okay...keeping in mind that I'm pretty new to Java, I have three
questions:

First, does "Sun JDK" mean the same thing as "Java SDK" (which is what
sun refers to on java.sun.com)?

Second, is javax.xml.* the sun equivalent of gnu.xml.* ?

Third, (and this may be more of a Linux question than a Java
question), since I haven't specified gnu.xml.xpath.* as an import, is
there some kind of translation going on behind the scenes to use gnu.*
in place of javax.* ?

Looking at the packages and classes in the gcj jre library in Eclipse,
I see both javax packages and gnu packages and classes (including the
"not found" one...and this is in my default workspace runtime
library).

I'm downloading java_ee_sdk-5_02-linux.bin as I write this.  I'll try
making that my default library and cross my fingers.
Oliver Wong - 11 Apr 2007 17:40 GMT
> ...okay...keeping in mind that I'm pretty new to Java, I have three
> questions:
>
> First, does "Sun JDK" mean the same thing as "Java SDK" (which is what
> sun refers to on java.sun.com)?

   More or less, yes. "Sun JDK" is to put emphasis on the fact that
BozoBits was recommending you use Sun's implementation of the JDK in
particular, as opposed to GNU's implementation. The term "Java SDK" loses
this emphasis, as Sun's JDK and Gnu's JDK are both Java SDKs.

> Second, is javax.xml.* the sun equivalent of gnu.xml.* ?

   Maybe. And more like the other way around. Sun invented Java, so
they're more or less the defacto standard around which all other Java
implementations are compared. GNU didn't like the fact that Java wasn't
open source, so they tried to make an open source alternative. Whether or
not they did a "good" job (in the sense that you can replace all
occurrences of gnu.xml.* with javax.xml.* and not uncover any bugs)
depends entirely on GNU.

> Third, (and this may be more of a Linux question than a Java
> question), since I haven't specified gnu.xml.xpath.* as an import, is
> there some kind of translation going on behind the scenes to use gnu.*
> in place of javax.* ?

   I don't know. I'm not familiar with the GNU class path.

> Looking at the packages and classes in the gcj jre library in Eclipse,
> I see both javax packages and gnu packages and classes (including the
[quoted text clipped - 3 lines]
> I'm downloading java_ee_sdk-5_02-linux.bin as I write this.  I'll try
> making that my default library and cross my fingers.

   If you're not sure whether or not you need EE, you probably don't need
EE (EE stands for Enterprise Edition). It might make your life simpler to
get SE (Standard Edition) instead. Certainly, you don't need EE to do XML
manipulation. You'll need EE if you're working with Tomcat, JSP, servlets,
or other web-app/web-service type stuff.

   - Oliver
drakaan@gmail.com - 11 Apr 2007 16:38 GMT
> > drak...@gmail.com wrote:
> > > Exception in thread "main" java.lang.NoClassDefFoundError:
[quoted text clipped - 10 lines]
>
> bozo bits

Okay...downloaded the 5.0.2 SDK and used that JRE in Eclipse, and the
classdefnotfound error went away.  I guess I should find a GNU java
developer to ask about the original problem (it'd be nice for things
to work by default, right?) with the GNU JRE.

Thanks for the help...now I just have to find out where a
nullpointerexception is coming from...if I get stuck again, I'll make
sure to ask here.  Thanks again.
Oliver Wong - 12 Apr 2007 16:11 GMT
> now I just have to find out where a
> nullpointerexception is coming from...

   Usually when you get an exception, you'll also get a stack trace which
should show the exact line number within each method in the call stack
where the exception was generated.

   There's an example stack trace, and a guide on how to interpret it, at
http://moinmoin.riters.com/JINX/index.cgi/Suggestions_20for_20Asking_20Questions
_20on_20Newsgroups#RepeatErrorsExactly


or http://tinyurl.com/3btw72

   - Oliver
drakaan@gmail.com - 12 Apr 2007 21:30 GMT
> <drak...@gmail.com> wrote in message
>
[quoted text clipped - 12 lines]
>
>     - Oliver

Right you are about "usually".  Being too diligent in exception
handling leaves you with less information than that.

I had a 'catch (Exception ex)' as the last in a series of catch
statements, which catches the nullpointerexception, and I was just
doing 'System.out.println(ex)', which strips the useful bits like line
number, etc, so all I got was the exception type with no context.

I'm back to doing actual programming thanks to you guys.  Much
appreciated.
Oliver Wong - 13 Apr 2007 14:48 GMT
>>     Usually when you get an exception, you'll also get a stack trace
>> which
[quoted text clipped - 13 lines]
> doing 'System.out.println(ex)', which strips the useful bits like line
> number, etc, so all I got was the exception type with no context.

   The Exception class has a method printStackTrace(), so you can replace
your "System.out.println(ex);" line with "ex.printStackTrace();" to get
more useful information. Unless you're writing server software which has
to be up "no matter what", I usually recommend just letting the exception
propagate all the way up, as the stack trace will automatically be printed
out once it reaches all the way to the top of the callstack without being
handled.

   It also gives the calling method more flexibility in trying to catch
and deal with the exceptions themselves.

   - Oliver
drakaan@gmail.com - 13 Apr 2007 21:06 GMT
> <drak...@gmail.com> wrote in message
>
[quoted text clipped - 30 lines]
>
>     - Oliver

I am, in fact, writing server software (a *nix daemon that processes
files in a directory as they get placed there by another daemon), but
I hadn't encountered printStackTrace yet.  I'll definitely make use of
that instead of the println lines I'm currently catching exceptions
with.  It'll save me adding debug print statements all over the place
when I'm trying to figure out which line in a block is throwing an
exception :).

I really appreciate the pointers.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.