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 23 of 23

Thread: Run Time Error

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Angry Run Time Error

    Hello ! I Tanmay not java begineer Programmer.I have done more program on different
    tools on jdk1.6 but when I uninstall this software & again installed the jdk new version jdk1.7.0_03
    on my computer.

    When I compile the Program on command Prompt then my Program was compile but when I did run it on
    command prompt then I got the error.So I am just showing' my command prompt details are given below :

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Tanmay Sinha>d:

    D:\>cd D:\Tanmay Java Programs\Core Java codes

    D:\Tanmay Java Programs\Core Java codes>javac Program1.java

    D:\Tanmay Java Programs\Core Java codes>java Program1
    Error: Could not find or load main class Program1

    D:\Tanmay Java Programs\Core Java codes>

    Please reply me......


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    Does the program have a package statement?
    If so you must consider it when using the java command.
    For simple program testing, comment out the package statement and try again.

  3. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Run Time Error

    And make sure you don't have wretched CLASSPATH variable hanging about.

    javac -cp . Program1.java
    java -cp . Program1

    The dash-cp-space-dot ensures that the current directory will be the classpath that the Java executable tools use.

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Location
    Behala, Kolkata
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    Make sure that you have this line : public static void main(String args[]) after the class program1.
    Also make sure that your file name should be program1.java

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Angry Re: Run Time Error

    Yes I wrote my code is given below :-

    class Prg1
    {
    public static void main(String args[])
    {
    System.out.println("HelloWorld");
    }
    }

    I have saved it by "Prg1.java" & aalso I compited it but getting the run time error Could not find or load main class Program1.

  6. #6
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    No... no package statements are used on the Program.Tell me briefly with examples.

  7. #7
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    Yes I wrote my code is given below :-

    class Prg1
    {
    public static void main(String args[])
    {
    System.out.println("HelloWorld");
    }
    }

    I have saved it by "Prg1.java" & aalso I compited it but getting the run time error Could not find or load main class Program1.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    Could not find or load main class Program1.
    Where is the class Program1?
    The code you posted has a class named: Prg1

    You should use that name when executing the java command: java Prg1

  9. #9
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Angry Re: Run Time Error

    Quote Originally Posted by Norm View Post
    Where is the class Program1?
    The code you posted has a class named: Prg1

    You should use that name when executing the java command: java Prg1


    I created a new folder Tanmay Java Programs & written a code shifted into another folder name Core Java Codes (D:\Tanmay Java Programs\Core Java codes).
    I used that name when excuting the java program as :

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Tanmay Sinha>d:

    D:\>cd D:\Tanmay Java Programs\Core Java codes

    D:\Tanmay Java Programs\Core Java codes>javac Prg1.java

    D:\Tanmay Java Programs\Core Java codes>java Prg1
    Error: Could not find or load main class Prg1

    This is the Error.I have shown it in detail.Plz help me coz I have to do the project on java....
    When I installed the java Program[(jdk-7u3-windows-i586) java SE Development Kit 7 windows X86)
    on my machine(Window XP Service Pack2) then after installation I looked Java folder in C-Drive
    (C:\Program Files\Java),In c Drive there are 2 folders available One is jdk1.7.0_03 and other is
    jre7.I used jdk1.7.0_03 & open its bin folder & then copy the Address of the bin as
    C:\Program Files\Java\jdk1.7.0_03\bin.Again I used right click on My Computer,Open properties,
    select Advance,Select Environment Variable then I looked the two options user variables for Tanmay Sinha and other is System variables,In System variables I choose Path & double click on Edit option ,After that
    showing other window Edit System Variable.In Edit System Variable typed Path at Variable name and
    at Variable value I paste the jdk bin folder
    C:\Program Files\Java\jdk1.7.0_03\bin
    then use ok.....
    After that I did program on command prompt & after successfull compilation I get error
    Error: Could not find or load main class Prg1.

    When I installed (jdk-7u3-windows-i586) java SE Development Kit 7 windows X86) on my machine then I also looked the other folder in c-drive(C:\Program Files\Oracle).In this folder there are 2 folders one is JavaFX 2.0 Runtime and other is JavaFX 2.0 SDK.
    Now hopefully u'll get the all information about java & solve my Problem easily.

  10. #10
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    I created a new folder Tanmay Java Programs & written a code shifted into another folder name Core Java Codes (D:\Tanmay Java Programs\Core Java codes).
    I used that name when excuting the java program as :

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Tanmay Sinha>d:

    D:\>cd D:\Tanmay Java Programs\Core Java codes

    D:\Tanmay Java Programs\Core Java codes>javac Prg1.java

    D:\Tanmay Java Programs\Core Java codes>java Prg1
    Error: Could not find or load main class Prg1

    This is the Error.I have shown it in detail.Plz help me coz I have to do the project on java....
    When I installed the java Program[(jdk-7u3-windows-i586) java SE Development Kit 7 windows X86)
    on my machine(Window XP Service Pack2) then after installation I looked Java folder in C-Drive
    (C:\Program Files\Java),In c Drive there are 2 folders available One is jdk1.7.0_03 and other is
    jre7.I used jdk1.7.0_03 & open its bin folder & then copy the Address of the bin as
    C:\Program Files\Java\jdk1.7.0_03\bin.Again I used right click on My Computer,Open properties,
    select Advance,Select Environment Variable then I looked the two options user variables for Tanmay Sinha and other is System variables,In System variables I choose Path & double click on Edit option ,After that
    showing other window Edit System Variable.In Edit System Variable typed Path at Variable name and
    at Variable value I paste the jdk bin folder
    C:\Program Files\Java\jdk1.7.0_03\bin
    then use ok.....
    After that I did program on command prompt & after successfull compilation I get error
    Error: Could not find or load main class Prg1.

    When I installed (jdk-7u3-windows-i586) java SE Development Kit 7 windows X86) on my machine then I also looked the other folder in c-drive(C:\Program Files\Oracle).In this folder there are 2 folders one is JavaFX 2.0 Runtime and other is JavaFX 2.0 SDK.
    Now hopefully u'll get the all information about java & solve my Problem easily.

  11. #11
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    Hey ! Man.....I am getting this Error first time......I still confuse because when my code does not run but why compiling process is successfully working on command prompt???????????

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    The OS is finding the javac and the java commands. Otherwise there'd be error messages.
    The javac command did not give an error. What .class files are there in the Core Java codes folder?
    Do a dir command in that folder to list its contents.

  13. #13
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    Prg1.class is a class file in the Core Java codes folder.
    yes..

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    Can you post what is shown in a command prompt for the dir command and the java command.

    I can't find a way to generate the error message you show when using the java command:
    Error: Could not find or load main class Prg1

  15. #15
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    ok..

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Tanmay Sinha>d:

    D:\>cd D:\Tanmay Java Programs\Core Java codes

    D:\Tanmay Java Programs\Core Java codes>javac Prg1.java

    D:\Tanmay Java Programs\Core Java codes>java Prg1
    Error: Could not find or load main class Prg1

    D:\Tanmay Java Programs\Core Java codes>

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    Where is the dir command output?
    Also enter: java -version

    Also show the contents of the Prg1.java file

  17. #17
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    I have compile & run the java codes on command prompt through that way I have sent u to showing detail....

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    If you don't run the commands I asked for and post the contents of the command prompt window when you are done, I can't help you. I'm here and you are there with your PC. The only way I can see anything from your PC is if you copy and paste it on the forum.
    I want to see all of it in one posting.

  19. The Following User Says Thank You to Norm For This Useful Post:

    Tanmaysinha (March 7th, 2012)

  20. #19
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Angry Re: Run Time Error

    I created a new folder Tanmay Java Programs & written a code shifted into another folder name Core Java Codes (D:\Tanmay Java Programs\Core Java codes).
    I used that name when excuting the java program as :

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Tanmay Sinha>d:

    D:\>cd D:\Tanmay Java Programs\Core Java codes

    D:\Tanmay Java Programs\Core Java codes>javac Prg1.java

    D:\Tanmay Java Programs\Core Java codes>java Prg1
    Error: Could not find or load main class Prg1

    This is the Error.I have shown it in detail.Plz help me coz I have to do the project on java....
    When I installed the java Program[(jdk-7u3-windows-i586) java SE Development Kit 7 windows X86)
    on my machine(Window XP Service Pack2) then after installation I looked Java folder in C-Drive
    (C:\Program Files\Java),In c Drive there are 2 folders available One is jdk1.7.0_03 and other is
    jre7.I used jdk1.7.0_03 & open its bin folder & then copy the Address of the bin as
    C:\Program Files\Java\jdk1.7.0_03\bin.Again I used right click on My Computer,Open properties,
    select Advance,Select Environment Variable then I looked the two options user variables for Tanmay Sinha and other is System variables,In System variables I choose Path & double click on Edit option ,After that
    showing other window Edit System Variable.In Edit System Variable typed Path at Variable name and
    at Variable value I paste the jdk bin folder
    C:\Program Files\Java\jdk1.7.0_03\bin
    then use ok.....
    After that I did program on command prompt & after successfull compilation I get error
    Error: Could not find or load main class Prg1.

    When I installed (jdk-7u3-windows-i586) java SE Development Kit 7 windows X86) on my machine then I also looked the other folder in c-drive(C:\Program Files\Oracle).In this folder there are 2 folders one is JavaFX 2.0 Runtime and other is JavaFX 2.0 SDK.
    Now hopefully u'll get the all information about java & solve my Problem easily.

  21. #20
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error

    I have sent the all detail...

  22. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    You are repeating yourself. I asked that you do a dir command and a java -version command when you do the other commands.

    Can you do those extra commands and post the output here?
    If you don't have a PC that you can use, don't waste my time by copying old posts. I would like the output from a new test. Otherwise come back later when you can do that.

  23. #22
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Angry Re: Run Time Error

    Quote Originally Posted by Norm View Post
    You are repeating yourself. I asked that you do a dir command and a java -version command when you do the other commands.

    Can you do those extra commands and post the output here?
    If you don't have a PC that you can use, don't waste my time by copying old posts. I would like the output from a new test. Otherwise come back later when you can do that.
    Hey ! Man,I did format my machine since i was getting more terrible thing due to java run time error after compilation.Now I installed the jdk1.7 software on window xp
    environment & copy the jdk bin address & paste it in system variable path.After that i did run the program & got output.Man now can u think more why i was getting run time error while I used the same procedure as before?

  24. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,646
    Thanks
    45
    Thanked 1,959 Times in 1,933 Posts

    Default Re: Run Time Error

    I have no idea how to get the error message you were getting.

Similar Threads

  1. I am having a hard time fixing this error
    By KuruptingYou in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 28th, 2011, 10:12 PM
  2. Help with run time error
    By white97 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: August 11th, 2011, 12:35 PM
  3. Run Time Error.
    By seymour001 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 10th, 2011, 12:10 PM
  4. [SOLVED] Run time error
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2011, 10:05 AM
  5. [SOLVED] Experiencing a run time error, don't know what the problem is
    By scooty199 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 3rd, 2010, 10:21 AM

Tags for this Thread