aspose file tools*
The moose likes Beginning Java and the fly likes just started Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "just started" Watch "just started" New topic
Author

just started

nicholas lee
Greenhorn

Joined: Mar 29, 2006
Posts: 4
Hi,

I'm a novice here. I just purchased Head First Java. I'm about 10 pages deep. I wrote the following

public class myfirstapp {

public static void main (String[] args) {
System.out.println("I rule!");
System.out.println("the world");
}
}

complied it and try to run the compiled file, but was returned this exception in thread "main" java.lang.NoClassDefFoundError: myfirstapp/class???


Please help me feel no so stupid.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

When you compile your program, you include the .java extension...

But when you run your program, do not include the .class extension. Just type...

Let us know if this clears it up.
[ March 29, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
nicholas lee
Greenhorn

Joined: Mar 29, 2006
Posts: 4
That didn't work. I still recieve the error

exception in thread "main" java.lang.NoClassDefFoundErorr: myfirstapp


Is there a better interface than using a c dos shell to run java from?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Maybe you should read this first:
http://faq.javaranch.com/view?HowToSetTheClasspath and add the current directory to your CLASSPATH.

This has no relation but try to name your classes with capital letters. Like MyFirstApp.java


[My Blog]
All roads lead to JavaRanch
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Satou kurinosuke:
Maybe you should read this first:
http://faq.javaranch.com/view?HowToSetTheClasspath and add the current directory to your CLASSPATH.


An alternate to setting that operating system environment variable is to use the cp (classpath) command line option:

java -cp . MyFirstApp

This causes the JVM to look in the current directory for class files.
[ March 30, 2006: Message edited by: Jeff Albertson ]

There is no emoticon for what I am feeling!
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
Just a simple observation that, your class name should start with uppercase.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by nicholas lee:
...I still recieve the error

exception in thread "main" java.lang.NoClassDefFoundErorr: myfirstapp

This is a different error than the first (which ended in "/class"). Check to make sure that:
  • You first changed to the directory that contians the .java and .class files (using the command cd followed by the directory -- for example: cd c:\myJava\tests), and...
  • A compiled .class file is actually in that directory (i.e., it compiled successfully), and...
  • The name of your file matches the exact case you are typing (for example, if your file is myFirstApp, then myfirstapp won't work).
  • Note: You should not have any need for a CLASSPATH variable at this point. Your PATH variable seems to be correct, because javac and java are recognized (giving you the errors).

    Getting your system set up is one of the more difficult hurdles in beginning Java. But once you get past this, I think you'll find that the Command Prompt is your best bet for now.
    nicholas lee
    Greenhorn

    Joined: Mar 29, 2006
    Posts: 4
    Thank you all for you help. Setting the class path work out. I see now that the error registering was just letting me know that java could not find the class I defined.


    Is there documentation I could find which would tell me more about the error messages java return?

    hopefully in a few weeks, I'll be the one responding instead of posting.

    thanks
     
    Don't get me started about those stupid light bulbs.
     
    subject: just started