File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java problem" Watch "java problem" New topic
Author

java problem

Greg Levine
Greenhorn

Joined: Feb 21, 2005
Posts: 21
About 3 days ago I reformatted because of some issues with some software I installed for a class. I reinstalled J2SE, Ant, and JDOM, and I didn't seem to encounter any problems. I started reimplementing my project using Eclipse and I noticed that everything worked fine, as long as I ran the program from Eclipse, until I tried to work with JDOM. For some reason, I couldn't get Eclipse to recognize it, even though I was doing everything just like the slides. So I removed all JDOM related lines of code to try to get back to where I was before I had these issues. I closed Eclipse and tried to compile and run the program from the command line. The program compiled, but didn't run. Six errors were found, none of which existed when running in Eclipse. So I went back to the HelloWorld application to figure out if I could run any program. I compiled HelloWorld.java with "javac HelloWorld.java" and that worked. Then I tried to run it with "java HelloWorld" and I received the following error:

"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"

This really confused me and after I couldn't find any solutions to this problem in a google search, I went ahead and uninstalled and reinstalled J2SE. I also got rid of Eclipse and NetBeans so that I could get rid of all Java related IDE's, which I thought could have caused the problem. After reinstalling J2SE I recreated the HelloWorld project but the same problem occurred. I really have no clue what is going on and this is coming a terrible time since I have to be sure that I can compile and run programs from the command line, so any help would be much appreciated. Thanks.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Greg Levine:
The program compiled, but didn't run. Six errors were found
Normally saying "the program compiled" means it compiled successfully -- there were no errors. Or do you mean there were runtime errors (exceptions)?
I compiled HelloWorld.java with "javac HelloWorld.java" and that worked. Then I tried to run it with "java HelloWorld" and I received the following error:

"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"
This is what java would report if HellowWorld had failed to compile. If you list the files, do you see "HelloWorld.class"? If not, it didn't compile.

Make sure you have the JDK version you installed and that it's located where you expect.If that all pans out, and javac is definitely not reporting errors, post your HelloWorld.java.
[ February 23, 2005: Message edited by: David Harkness ]
Greg Levine
Greenhorn

Joined: Feb 21, 2005
Posts: 21
Normally saying "the program compiled" means it compiled successfully -- there were no errors. Or do you mean there were runtime errors (exceptions)?

There were no exceptions. What I meant was that no errors showed up when I called "javac MyProject.java". The errors only appeared when I called "java MyProject". I was under the impression that any compile errors would appear on the javac call, but I guess I was wrong.

This is what java would report if HellowWorld had failed to compile. If you list the files, do you see "HelloWorld.class"? If not, it didn't compile.

The class file does exist, so apparently it compiled correctly.

Make sure you have the JDK version you installed and that it's located where you expect.

javac -version produces:

javac 1.5.0_01
javac: no source files
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are u
sed
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release

-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system

java -version produces:

java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

My environment variables appear to be set correctly.

If that all pans out, and javac is definitely not reporting errors, post your HelloWorld.java.

class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Greg Levine:
What I meant was that no errors showed up when I called "javac MyProject.java".
So it did compile successfully, you were correct.
The errors only appeared when I called "java MyProject".
Can you post the errors you received, or did you get the same "NoClassDefFoundError: MyProject" error?

Everything you posted looks fine. A wild suggestion is to use an actual package for your HelloWorld. I'm totally reaching with that one, but that's all I can think of as it's past my bedtime.

I'd tell you to reinstall the JDK if you hadn't done it already. You could try uninstalling, use RegEdt32 to wipe the registry keys, and reinstall, assuming you're running Windows.
Greg Levine
Greenhorn

Joined: Feb 21, 2005
Posts: 21
Can you post the errors you received, or did you get the same "NoClassDefFoundError: MyProject" error?

I restarted my program and got rid of the code I was using before, so I can't recreate the previous errors. All I get now is the "NoClassDefFoundError: MyProject" error. I wasn't that far into the project, so I didn't care to keep what I had done. Anyways, I'm more concerned with figuring out how to get any program to compile right now, which is why I'm focusing on the HelloWorld application. I only posted the stuff about my project to give enough information about the steps leading up to my error. It should run without adding it to a package, especially since it did so before all of this. And I've already tried reinstalling the JDK. I'll just have to hope my professor has an idea of what is going on tomorrow. Thanks for your suggestions.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
It sounds like a classpath issue.

For the simple HelloWorld example with no packages and running javac and java from the directory with the classes in it I just set the classpath to include the current directory:

set classpath=.

How To Set Classpath FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java problem