Results 1 to 11 of 11
Like Tree5Likes
  • 1 Post By JosAH
  • 1 Post By JosAH
  • 1 Post By JosAH
  • 1 Post By JosAH
  • 1 Post By DarrylBurke

Thread: Help! I got an error when I try to execute a java!

  1. #1
    matiaz14 is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Help! I got an error when I try to execute a java!

    Help Please!

    I am a begginer in all these of Programming in Java. I can compile my programs , but when I got to open them i got a message that says ...Error Main class not found.. Or something like that
    I would really appreciate your help!
    Thanks

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help! I got an error when I try to execute a java!

    Please show us the exact error message and show us what you did that caused the error. 'or something like that' isn't much help.

    kind regards,

    Jos
    matiaz14 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    matiaz14 is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: Help! I got an error when I try to execute a java!

    I am so sorry , but I am from chile and I got the program in spanish (as all my progras). Thats why I cannot put the exaxt thing...
    Well I have many java Programs. Some of them are applets( they all work), and some are java `programs (none of them work). For example This one...
    public class HelloText
    {
    public static void main(String[] args)
    {
    System.out.println(" Hello World!");
    }
    }

    I can complie it perfectly with javac, but when I try to execute it I got the error (in english it must be something like this) cannot find the main class HelloWorld

    Thanks for helping

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help! I got an error when I try to execute a java!

    The name of your class is HelloText, not HelloWorld.

    kind regards,

    Jos
    matiaz14 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    matiaz14 is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: Help! I got an error when I try to execute a java!

    sorry... the error says: cannot find the main class HelloText


  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help! I got an error when I try to execute a java!

    Quote Originally Posted by matiaz14 View Post
    sorry... the error says: cannot find the main class HelloText

    Check the directory where you compiled the source file HelloText.java; does it contain a file HelloText.class?

    kind regards,

    Jos
    matiaz14 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    matiaz14 is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: Help! I got an error when I try to execute a java!

    It does have the a file called HelloText.class. It created when I compile.
    I tried moving the file to the desktop, but still the same...

    All these errors started when I beggined trying java with another pc (this one). I had to install Textpad, and put javaja as internal and external command...

    I dont know if it has to be because of that...

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help! I got an error when I try to execute a java!

    Store that .class file in an ordinary directory (to keep thing simple). Using a command prompt, go to that directory and first type:

    Java Code:
    java -version
    Show us the output; next type:

    Java Code:
    java HelloText
    Show us the results.

    kind regards,

    Jos
    matiaz14 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    matiaz14 is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: Help! I got an error when I try to execute a java!

    When I put java -version the result was...

    java version !1.7.0_03"
    Java<TM> SE Runtime Enviroment (build 1.7.3_03-b05)
    Java HotSpot(TM) 64-Bitt Server VM (build 22.1-b02, mixed mode)


    Then , with Java HelloText
    I got the error.. cannot find the main class HelloText

    Jos, I am pretty sure what I am doing wrong It has to do withe variable CLASSPATH...
    bacause 5 minutes ago, I edited the value of CLASSPATH , I added the direction exactly where the class file is. So It was like this..
    CLASSPATH - C:\Program Files\Java\jdk1.7.0_03\bin;C:\Matias\Java\Exercises\Chapter 2\HelloText
    and It workd perfectly!
    So i belive that my main classes are not saving in the folder bin (of java)....
    Idk How to solve this problem..
    Thanks for the help

  10. #10
    matiaz14 is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: Help! I got an error when I try to execute a java!

    I FIXED IT!!!
    i DONT KNOW WHY IT HAPPENS!!
    i DELEAT THE USER VARIABLE CALLED CLASSPATH, AND NOW ALL MY PROGRMS WORK PERCTLY!
    why is that?

    thanks jos for the help!

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Help! I got an error when I try to execute a java!

    Because if you define a system variable for CLASSPATH, the Java runtime will only look on that path for class files or jar files containing classes.

    It's usually a bad idea to set the CLASSPATH, but if required for some reason, it should contain the 'current working directory' represented by '.' (dot).

    And no matter how excited you may be, try not to shout. Bold all-caps offends the eyes.

    db
    matiaz14 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. how to execute the Java program to 0 sec?
    By yanipra in forum New To Java
    Replies: 4
    Last Post: 03-01-2011, 09:33 AM
  2. Error execute command through jsp
    By rahid in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-21-2010, 03:20 AM
  3. NetBeans 6.8 Execute through OTA error
    By Chirieac in forum NetBeans
    Replies: 0
    Last Post: 01-04-2010, 02:56 PM
  4. error stack when I try to execute my code
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 08:32 PM
  5. Execute a new program in java
    By mathias in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 05:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •