• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

just started

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
nicholas lee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a simple observation that, your class name should start with uppercase.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    I've never won anything before. Not even a tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic