Results 1 to 12 of 12
  1. #1
    java_aim is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Error: Could not find or load main class Test.class

    I could compile Test.java; but I couldn't run the corresponding Test.class
    Can anybody tell me why?

    Test.java contains:

    import javax.swing.JOptionPane;

    class Test{
    public static void main(String [] args){
    JOptionPane.showMessageDialog(null,"Hello World!");
    }
    }

    //EOF

    When I tried to run, the resulting message is:
    Error : Could not find or load main class Test.class

    Can somebody help me out?

    Thank you in advance.

  2. #2
    java_aim is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Error: Could not find or load main class Test.class

    I ran by typing: "java Test.class"

    Has there been anything wrong?

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Error: Could not find or load main class Test.class

    Java Code:
    java -cp . Test

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Error: Could not find or load main class Test.class

    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    java_aim is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Error: Could not find or load main class Test.class

    Quote Originally Posted by masijade View Post
    Java Code:
    java -cp . Test
    Could you please tell me a reason why we have to use this command in order to run a java program?

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Error: Could not find or load main class Test.class

    Quote Originally Posted by java_aim View Post
    Could you please tell me a reason why we have to use this command in order to run a java program?
    See the tutorials.

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Error: Could not find or load main class Test.class

    Quote Originally Posted by java_aim View Post
    Could you please tell me a reason why we have to use this command in order to run a java program?
    Is there any reason why you are asking this? You have to be more specific when asking these questions.

    I can *guess* that you are thinking about regular applications which you run by just double clicking on a shortcut icon or an executable, while for your Java application you all of a sudden have to run this user unfriendly command. Am I guessing correctly?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    java_aim is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Error: Could not find or load main class Test.class

    On windows, I can create a bat file (*.bat) saying this command (java -cp . Test) and then I can just double click on that bat file and then the entire program will smoothly run!

    Thank you all very much anyway for all of your friendly help!!!

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Error: Could not find or load main class Test.class

    you can also create an executable jar and not have to bother with scripts or commands at all.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    java_aim is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: Error: Could not find or load main class Test.class

    Can a jar file be directly executatble? How to create one? Can you tell me a little bit? so that i can do the same please..

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

    Default Re: Error: Could not find or load main class Test.class

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

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Error: Could not find or load main class Test.class

    Quote Originally Posted by java_aim View Post
    Can a jar file be directly executatble? How to create one? Can you tell me a little bit? so that i can do the same please..
    or google "java executable jar". It is so easy to find information nowadays man...
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Error: Could not find or load main class
    By iSamir in forum New To Java
    Replies: 16
    Last Post: 06-25-2013, 05:39 AM
  2. Error: Could not find or load main class Test
    By java_aim in forum New To Java
    Replies: 2
    Last Post: 11-17-2012, 10:25 AM
  3. Error:Could Not Find or Load Main Class
    By vickyv200 in forum New To Java
    Replies: 3
    Last Post: 08-29-2012, 01:10 AM
  4. Error: could not find or load main class
    By sloppygecko in forum New To Java
    Replies: 3
    Last Post: 08-08-2012, 03:11 PM
  5. Error: Could not find or load main class
    By ITSlave in forum New To Java
    Replies: 4
    Last Post: 09-15-2011, 09:47 AM

Posting Permissions

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