Getting NoClassDefFoundError
Hi,
I am trying to run a simple Java Application in my system , I am coding on Textpad and using jdk1.6.0_37. I am able to compile my code, but whenever I am trying to run the application I am getting NoClassDefFoundError. I also tried running it from the command prompt explicitly defining the classpath etc. but still getting the same error. Can anybody advise me on where I am doing wrong?
Thanks
Re: Getting NoClassDefFoundError
It could be a couple of things, no main() in your class, you could be invoking the wrong classfile, wrong class name, classpath issue, etc...
can you post a sample or all of your code so that we can help find the problem?
Don't forget to use the [ CODE][/ CODE] (without the spaces) markers to format your code properly. :-)
Re: Getting NoClassDefFoundError
hi,
I am trying with the simplest of Java Codes.. the HelloWorld one :) I guess something is wrong with my environment setup, but can't get into it. I have also set the Environment variables.
Code:
public class Test{
public static void main(String[] args){
System.out.println("hello swaralipi");
}
}
Re: Getting NoClassDefFoundError
hmm... ok looks correct...
so you should be saving the file as:
Test.java
This tells your java compiler it's a java source file we are working with...
Then attempt to compile at the command line as:
javac Test.java
this should output your Test.class file...
which is the java bytecode that runs on the JVM (Java Virtual Machine) and is really part of the magic to java that makes it so portable to so many devices! Google this to learn more!
you would then run the program by doing:
java Test
This invokes the java runtime environment on your computer and fires up the JVM, which then executes your code and displays it's output to your cmd prompt (console).
:)
Hope that helps, and welcome to Java!
EDIT: do all this from the command line and make sure to cd (change directory) to wherever you saved your Test.java file!
Re: Getting NoClassDefFoundError
Hi swaralipi, I've added "code" tags to your post. When you post code put [code] at the start of the code and [/code] at the end. That way the forum software will display the code in a readable way.
There is nothing obvious wrong with that code. As you say the problem may lie with the environment - including the commands you are using to compile and run the code. So, say what operating system you are using, the values of java related environment variables (PATH and CLASSPATH) and what commands you are using to compile and run the code. Describe the output that results from running those commands: in fact as much as possible copy and post the commands and their output. (This is another place for the [code] ... [/code] tags to preserve formatting).