Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

can anyone tell me why I am getting this error

  Asked By: Madeline    Date: Feb 05    Category: Java    Views: 1163

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

public class TextPadTest{
public TextPadTest(){out.println ("this is a test");}
public static void main(String[] args)
new TextPadTest();



9 Answers Found

Answer #1    Answered By: Adalwen Fischer     Answered On: Feb 05

there is no class  like "out"

instead use System.out.println. it worked in my case.

precaution: ensure that the "s" is uppper case in System. I
used "system" and got an error  which was not very apparent and spent
around 30 mins rectifying it.

Answer #2    Answered By: Dylan Evans     Answered On: Feb 05

but I dont know what
happened to the System.out.println part of that
statement, in fact I am getting that error
regardless. The Program Compiles and looks like it
should run but does not.

If the line was out.println it would not even compile.

I am afraid you are looking at a copy that is the
result of me trying everything after a great deal of

Answer #3    Answered By: Kerry Wright     Answered On: Feb 05

I just copied your program and added the System as you were advised -- the
program looks like this:

public class  TextPadTest{
public TextPadTest(){System.out.println ("this is a test");}
public static  void main(String[] args)
new TextPadTest();

This compiles and runs without problems and the results are

this is a test

written to standard out. Clearly something else is wrong. How are
you invoking the call? It should be something like

java TextPadTest

If it's something other than that, you need to make sure that you're calling
the class where it exists (that is, the .class file, not the .java file).
If that's
what you've called, make sure that your system can find the class -- you
might have a problem with your classpath.

Answer #4    Answered By: Miriam Green     Answered On: Feb 05

I want u to remember one thing(V imp).

java.lang package is loaded by default.

Which means that methods under this package can be accesses without
defining the package.

eg - System.out.println("");

what does this mean - System(a class) is in java.lang

This class  has a "field" (not a class) "out" which is of the type
PrintStream. So out inherits the methods of PrintStream. PrintStream
has a method println().

This is how System.out.println() works.

In ur program u have used out.println();

how will the compiler know which package to check the "out function

Actually out is in the package java.lang.System.

is it clear.

Check java  API for more details


Answer #5    Answered By: Alberta Miller     Answered On: Feb 05

i suspect if ur class  path is set properly.
make a batch file (DOS) of following contents

path = c:\jdk1.4\bin;c:\jdk1.4\lib;.;
set Classpath=c:\jdk1.4\jre\lib\*.jar;.;
set java_home=c:\jdk1.4

Change the path ur JDK in the above code snippet.

Got to command prompt and run this batch file.
After this, try to comple ur code.
Let me know what happens.

Answer #6    Answered By: Debbie Reyes     Answered On: Feb 05

It's very hard to see what it is supposed to do. You
initialize a class  with a constructor, meaning that it
should go "this is a test  when it's constructed". What
is out a member of, and where should it be printed?
Try System.out, so that it will be displayed
console-wise part of the java  lang and then move it to
you class.

If this doesn't work, try some Swing classes, as they
have a lot of textpad-like classes like JEditorPane,
JTextPane etc, you'll probably find something that you

Answer #7    Answered By: Leroy Schmidt     Answered On: Feb 05

u have run the file like this

java TextPadTest.class

when using java  command just specify the classfilename without extension
like this.

java TextPadTest
this will solve ur problem.

Answer #8    Answered By: Edwin Chavez     Answered On: Feb 05

No, the .class extension should not be there.

Instead run the file like this

java TextPadTest

but, this is confusing, use the compiler with
extension, like this (of course before the one above)

javac TextPadTest.java

but of course you knew that one

Answer #9    Answered By: Burk Martin     Answered On: Feb 05

u have run the file like this

"java TextPadTest.class"

when using java  command just specify the classfilename without extension.

this will solve ur problem.

Didn't find what you were looking for? Find more on can anyone tell me why I am getting this error Or get search suggestion and latest updates.