Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exception in thread "main" java.lang.noclassdeffounderror:

Status
Not open for further replies.

josee411

Programmer
May 12, 2003
18
BE
hi,
i install j2sdk-1_3_1_08 window-i 586 on win 2000.
i tried to compile my program on MSDOC but it doesn't work, please help:
exception in thread "main" java.lang.noclassdeffounderror:hello
 
Java is case sensitive. Make sure your java file is called hello.java, not Hello.java or HELLO.java.
 
it still doens't work, i tried another example, my java doesn't also accept javac, example:
bin\javac hello.
 
javac needs a .java file as argument, ie javac Hello.java
Also, make sure the path and classpath are correct
 
hi,
would explain to me this"javac needs a .java file as argument, ie javac Hello.java
Also, make sure the path and classpath are correct".
sorry, i'm beginner on java,
what does it mean classpath,?
where i can find it??
sincerly salutations.
 
1. javac file.java is the required syntax. The extension is kind of a "final check" to let the compiler know that you are compiling a java file.

2. classpath can be set under control panel on windows. add a variable (if not there) called CLASSPATH and add the value to point to this directory. For instance, I use servlets.jar (comes with tomcat) for my app, so I have this classpath added:-

CLASSPATH c:\tomcat41\common\lib\servlet.jar

3. add path stmt in your environment settings:-

path c:\jdk14\bin

so if you're running from the command prompt, it can find all the needed exe's like javac.exe etc.




 
hi,
i checked out that java was well installed with all packages:
i have this classpath: c:\tank\binso, i tried to compile this:
c:\tank\bin\javac casting.java
i have the following error:
error: cannot read : casting.java
 
hi, to maxpower, please would you explain more your message:
classpath can be set under control panel on windows. add a variable (if not there) called CLASSPATH and add the value to point to this directory. For instance, I use servlets.jar (comes with tomcat) for my app, so I have this classpath added:-

CLASSPATH c:\tomcat41\common\lib\servlet.jar

3. add path stmt in your environment settings:-

app??
sevlet.jar???
 
this is my setting for windows xp.

under user variable, add this:

Variable Value
-------- ----------
CLASSPATH c:\tomcat41\common\lib\servlet.jar

if you don't have CLASSPATH defined for other apps. If it's already there. do this:

Variable Value
-------- ----------
CLASSPATH c:\otherapp;c:\tomcat41\common\lib\servlet.jar

notice the ;

this should allow you to compile the app.

To make your life easier, I would suggest for you to get an IDE, like Intellij idea. It sets up everything for you nicely.

2. error in casting.java

show me the codes and let me see what's wrong with it.

later





You can't bring back a dead thread!
 
here you re:
public class hello
{
public static void main (string[] args)
{
system.out.println("bonjour de Reda");
}
}
i saved it in c:\tomcat\lib
 
It should be "String" not "string". Java is case sensitive.
Basically the compiler cannot find a static method:-

public static void main (String [] args){}

in your class file.

~za~
You can't bring back a dead thread!
 
hi,
sorry to be late for the answer.
i still have the same problem, as i said i'm beginner on java.
please, would you describe to me the good version of java that you have on your computer, where did you take it from?,
and provide me some simple examples so i worked with.
thank you for replying.

 
hi,
i saved my class "hello" in classpath :
c:\j2sdk1.4.0_01\bin
and i have the following error when i tried to compile it.
javac : invalid flag : hello
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
-O Optimize; may hinder debugging or enlarge class file

-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are us
ed
-classpath <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
-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
-help Print a synopsis of standard options

 
First off - Read The Manual, buy a book or something !

Second. Start again.

open a console /msdos window.
(Don't type the actual quotation marks for the following)

Type &quot;set JAVA_HOME=C:/j2sdk1.4&quot; (The directroy name will need to change to where you installed your JDK)

Type &quot;set PATH=%PATH%;%JAVA_HOME%\bin&quot;
Type &quot;set CLASSPATH=%CLASSPATH%;JAVA_HOME%\jre\lib&quot;

These variables are called &quot;environment variables&quot; and lets the Java compiler and interpreter know where the programmes necessary to compile and run your code live. Thet should ideally be set permanently by going to Start >> Control Panel >> System and finding the tab for &quot;Environment Variables&quot;.

Go to a directory such as C:\tmp and create a new file called &quot;Hello.java&quot;
In this file add the code below :

public class Hello {
public static void main(String[] args) {
System.out.println(&quot;bonjour de Reda&quot;);
}
}

Then type &quot;javac Hello.java&quot;

This should have created file called &quot;Hello.class&quot;

Then type &quot;java -cp . Hello&quot;

That should have worked.
If not, I'd give up !
 
Firstm thanks for replying;
sure, i have a book, but sometimes it isn't clear on a book.
i did all the instructions to the letter.
so i have this following lines:

C:\j2sdk1.4.0_01\bin>java -cp.hello
Unrecognized option: -cp.hello
Could not create the Java virtual machine.
 
put a space after -cp and another space after . , so it you look like:

java -cp . Hello

hope this helps.
 
Take a look of my test below.
Check whether or not you type <ClassName>.class as performing a java class.
Maybe it is helpful for you.
Recommend you a good Java book: Java in a Nutshell.


C:\Documents and Settings\ertjimc\My Documents\WorkShop\Experiences\Java\StandaloneScribble>javac StandaloneScribble.java
Note: StandaloneScribble.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

C:\Documents and Settings\ertjimc\My Documents\WorkShop\Experiences\Java\StandaloneScribble>java StandaloneScribble

C:\Documents and Settings\ertjimc\My Documents\WorkShop\Experiences\Java\StandaloneScribble>java StandaloneScribble.class
Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: StandaloneScribble/class

C:\Documents and Settings\ertjimc\My Documents\WorkShop\Experiences\Java\StandaloneScribble>



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top