> So you would have to execute the command in this way :
> javac HelloWorldApp the class loader would look for a file with that
> name and a .class extension
A typo maybe? It should be java HelloWorldApp
> Exception in thread "main" java.lang.noclassdef
This question has been asked a lot of times on almost all java related message boards. Have you tired a web search with the given error message? Have you tried the solutions suggested in the existing threads?
BTW, the `java' command expects a "package qualified" class name and not just a class name. So if you are using a package, make sure you use the fully qualified class name when invoking `java'. If not, then executing the `java' command from the same directory in which the class file lies shouldn't be a problem as such.
Also, is the NoClassDefFoundError error thrown for the main class or some other class which the main class is using? In this case, you might have unresolved runtime dependencies which you will have to resolve by setting the appropriate classpath entries.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Post the code of the class "as it is" without *any* modification, including the package declaration. Also paste the *exact* error message along with a screenshot of the entire session.
This shouldn't be happening if you are well aware of the points I mentioned in my previous post.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
I think your classname is different then your .java file. After you compiled a .java file, a .class file will be produced. Determine the name of .class file and try to execute with,
>java classname
NOTE: Lets us know the version of jdk you are using.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
Let me again point you to my first post in this thread which clearly mentioned:
BTW, the `java' command expects a "package qualified" class name and not just a class name. So if you are using a package, make sure you use the fully qualified class name when invoking `java'. If not, then executing the `java' command from the same directory in which the class file lies shouldn't be a problem as such.
Does that ring a bell? Think what could have gone wrong, give it a second try and reproduce the entire session again in case you still face problems.
BTW, it's advisable to have the project placed in your personal folder; something like D:\personal\projects to avoid dealing with excessively long paths which IMO is messy.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Because of this statement
package helloworldapp;
..
..
you have to change the your method of compilation and also execution.
If package is mentioned then your .class must be placed under the package named folder.
Now, compile your program
>javac HelloWorldApp.java -d .
>java helloworldapp.HelloWorldApp
Note:
>javac HelloWorldApp.java -d .
where, -d option create a package folder and
. means current folder
>java helloworldapp.HelloWorldApp
If class definition placed inside the package then qualify the class with package name.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
Posting complete solutions never has and never will help. How about giving the OP a chance to try out a few things before handing out a solution?
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Because of this statement
package helloworldapp;
..
..
you have to change the your method of compilation and also execution.
If package is mentioned then your .class must be placed under the package named folder.
No it doesn't. It is convention to do it that way, but you don'thave to. You could place every one of your Java files in the same folder, or all of them in wildly scattered directories around the system, you would have a hard time compiling all of them at the same time, you'd probably have to compile one at a time, in the proper order, using the "-d" option, but you could do it, if you really wanted to.
Now, compile your program
>javac HelloWorldApp.java -d .
>java helloworldapp.HelloWorldApp
Note:
>javac HelloWorldApp.java -d .
where, -d option create a package folder and
. means current folder
>java helloworldapp.HelloWorldApp
"-d" doesnot mean create a package folder, and using "-d ." is absolutely meaningless, as that is the default anyway. The "-d" option is so that the compiled class files do not appear "in place", but rather somewhere else. I.E. You have a folder containing a src folder and a bin folder, you cd to the source folder and then use "-d /path/to/bin" to have the compiled class files appear (with a full package directory structure) under bin, rather than in place under src. Don't forget, however, to include "-cp /path/to/bin" on the javac commands, however.
If class definition placed inside the package then qualify the class with package name.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494