error with my first program


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 15 of 15

Thread: error with my first program

  1. #1
    Join Date
    Oct 2006
    Posts
    8

    error with my first program

    i downloaded the j2sdk-1_4_2_11-nb-5_0-win set it up on my pc am runnin winXP am learnin from how java how to program 5th edition but i keep gettin this error when i try to run the simple welcome prog.
    "Exception in thread "main" java.lang.NoClassDefFoundError: welcome/java"
    if any one can help plz do it

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    The interpreter is looking for a class called "welcome/java" which is supported in the "main" method of your class and cannot find it. Sounds as if there is a typo in your class file.

  3. #3
    Join Date
    Oct 2006
    Posts
    8

    wut class

    the book didnt tell me to make any classes here is the code am tryin to run
    public class welcome1

    {

    public static void main( String args [])

    {

    System.out.println("welcome to java programming");

    }

    }

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    How are you executing your program? (in NetBeans or at the command prompt?)

  5. #5
    Join Date
    Oct 2006
    Posts
    8

    command

    command prompt

  6. #6
    Join Date
    Oct 2006
    Posts
    8

    javac

    i used the javac command after settin the path and classpath and i get that error
    welcome.java:1: class welcome1 is public, should be declared in a file named wel
    come1.java
    public class welcome1
    ^
    1 error
    am i missin somethin?

  7. #7
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    No, that is absolutely correct. The name of the java file should be the name of the class.

  8. #8
    Join Date
    Oct 2006
    Posts
    8
    then wuts wrong lizard0o_1@hotmail.com add me plz we can talk there so i can get wut am missin

  9. #9
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    is your java code file named welcome1.java? The compiler doesn't think so.

  10. #10
    Join Date
    Oct 2006
    Posts
    8
    no my file named welcome.java not welcome1 and the command i use in cmd is java welcome.java or javac welcome.java

  11. #11
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Then either change the name of the file to welcome1.java, or change the line in your code

    public class welcome1

    to

    public class welcome

  12. #12
    Join Date
    Oct 2006
    Posts
    8
    thanx alot for ur help but still havin a prob i changed the file name to welcome1 when i call command javac welcome1.java it created a welcome1.class file but no out put on the screen and when i call the java welcome1.java i get the first error

    F:\sana 4\start my java\welcome>javac welcome1.java

    F:\sana 4\start my java\welcome>java welcome1.java
    Exception in thread "main" java.lang.NoClassDefFoundError: welcome1/java
    wut do u think it is this time

  13. #13
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    When you invoke the java interpreter (java ... ) the command is "java welcome1" - you are "executing" the welcome1.class file produced by the compiler.

    The compiler, if there are no error messages or warnings, just returns the command prompt. So what you are seeing is the expected outcome of the compilation of a properly formed program.

    So, now try to run the compiled code by typing

    java welcome1

    at the command prompt.
    Last edited by nspils; 10-28-2006 at 12:07 PM.

  14. #14
    Join Date
    Oct 2006
    Posts
    8
    it worked at last my first code in java run with no errors lol thanx alot

  15. #15
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    And, I trust, far from the last code you will run in java with no errors. Good luck in your exploration of the language!

Similar Threads

  1. soft drink Vending machine program
    By divagoddess in forum C++
    Replies: 5
    Last Post: 08-14-2009, 03:12 PM
  2. Help with a program
    By stormswimmer in forum Java
    Replies: 2
    Last Post: 01-02-2006, 03:17 PM
  3. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM
  4. How can I build copy protection into my program
    By W.Pierce in forum VB Classic
    Replies: 1
    Last Post: 12-11-2001, 08:28 AM
  5. Replies: 0
    Last Post: 12-15-2000, 10:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center