Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Can compile But can't Execute my programs need advice

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Location
    nigeria
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can compile But can't Execute my programs need advice

    hello everyone just a beginner in java having a problem i have started following instruction on writing programs but when ever i finish writing them i compile them without errors from .java files to .class files . But when i try to execute them my command prompt reads out (error: could not load main class ) this upsets me so im wondering if anyone could help me out with this problem.,.... Thanks
    Last edited by jps; August 23rd, 2013 at 03:20 PM. Reason: removed profanity


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,285
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: Can compile But can't Execute my programs need advice

    What command are you using at the command line to run the compiled file? If the file is named FirstProgram.java, the command to compile is:

    > javac FirstProgram.java

    Then to run the program

    > java FirstProgram

    Note, the '>' is intended to represent a prompt, not something you should type at your actual command prompt.

    You may post the actual session from your command shell using copy/paste if you'd like. That might be helpful.

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Can compile But can't Execute my programs need advice

    Hello.
    Also, if you are using packages then you will need to invoke the class along with the package name.
    For example, if the class is com.abc.Class1 then you will need to type "java com.abc.Class1" where com is the sub-directory in the present directory.

    Syed.

  4. #4
    Junior Member
    Join Date
    Aug 2013
    Posts
    26
    My Mood
    Where
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: Can compile But can't Execute my programs need advice

    Check the location of your .java files, are there .class files there also?

    --- Update ---

    Also, check out this video on Youtube and follow the instructions carefully.

  5. #5
    Junior Member
    Join Date
    Aug 2013
    Location
    nigeria
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can compile But can't Execute my programs need advice

    when i intend to run it the way u jst showed it shows me error could not load main class like that.

    --- Update ---

    yeah there are class files there could that be the problem?.??

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Can compile But can't Execute my programs need advice

    Quote Originally Posted by Jaynas View Post
    yeah there are class files there could that be the problem?.??
    The .class files are required, so that is not the problem. I would say read post #3

  7. #7
    Junior Member
    Join Date
    Aug 2013
    Location
    nigeria
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can compile But can't Execute my programs need advice

    thanks For your help peeps The Classpath was the problem ... Now executing easily thanks alot..

Similar Threads

  1. Please help me! i am unable to compile and execute java files in command prompt
    By Sunanda Naik in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 24th, 2013, 09:42 AM
  2. Implement 2PC Protocol - Unable to Compile and Execute
    By The.Reaper in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 29th, 2012, 07:25 AM
  3. some advice about building more complex programs
    By derekxec in forum Java Theory & Questions
    Replies: 2
    Last Post: July 22nd, 2012, 10:22 AM
  4. how to execute multiple different queries in one execute?
    By Sakina in forum JDBC & Databases
    Replies: 1
    Last Post: June 9th, 2012, 10:40 AM
  5. What's wrong. Compile Ok but error when execute.
    By hantuapi in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 1st, 2011, 06:33 AM