Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError =(

 
Leroy J Brown
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay friends,

So I'm rather confused about this class loader process and why it doesn't want to go about its business in the manner I expect. I normally use eclipse and I suppose it has become a crutch as this problem demonstrates.

I have read How To Set The Classpath
I can run any project I want in eclipse just fine. However I can't run anything from the command line as I want to. Below should be an image I took of my classpath side by side with my CMD line. Here you can see:

1) Searching for my desired file
2) evidence that such a file exists in this directory
3) me attempting to call this class's main method
4) the error
5) my CLASSPATH variable showing clearly that ".;" ie my current directory is part of the path and therefor (I thought) the class loader should be able to find it.

advise on how to solve this problem would be greatly appreciated.

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tristan,

That "wrong name" message is actually telling you that Java *did* find the class file, but it wasn't the file that Java expected. You asked it to run the class named GetPath, and it found the file GetPath.class, but the file does not contain the class named GetPath -- it contains the class named com.tristanjrouse.archive.GetPath .

The general solution to this is to "cd" into JavaSandbox\bin and then run the class using its full name; i.e.,

C:\ ...JavaSandbox\bin> java com.tristanjrouse\archive\GetPath

and that will work just fine!
 
Leroy J Brown
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest!

Thanks much for your reply. Just so that I understand what is happening here, when you say that Java found the class but it had the "wrong name"... does Java determine this "name" by its package statement? if not, how does it decide how much of the fully qualified path is included in the class's "name"?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tristan Rouse:
... does Java determine this "name" by its package statement? ...

Yes, the fully qualified package name is part of the fully qualified class name.

JLS 6.7...
The fully qualified name of a top level class or top level interface that is declared in a named package consists of the fully qualified name of the package, followed by ".", followed by the simple name of the class or interface.
 
Leroy J Brown
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much to both of you for your replies!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic