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

Thread: cmd prompt exception "could not find or load main class test.java"

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    My Mood
    Happy
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Post cmd prompt exception "could not find or load main class test.java"

    Hello, I'm getting the exception in cmd prompt while running the java program even after it is compiled successfully. I don't know why it can't find the .class file when .java file was available a moment before. I read so many threads relating to this exception and i also did as they said to recreate new java file and compile and run it. But then also it is not working properly. It was working good before 3 months. From last three months this exception has become permanent. Please help me to run files through command prompt. Since it is not working i'm using netbeans now



    Thanks in advance


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: cmd prompt exception "could not find or load main class test.java"

    Did you use the javac command to compile the program:
    javac test.java
    if there is no error message, the above creates a test.class file
    To execute that code enter:
    java test

    If there are problems:
    On Windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Padmahasa (September 2nd, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    My Mood
    Happy
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: cmd prompt exception "could not find or load main class test.java"

    Hello, Thank you for your solution i did as you said but i'm getting this error again. The below Text is copied from command prompt as u said.

    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\VJS>I:

    I:\>cd softys

    I:\Softys>cd java

    I:\Softys\java>cd javademos

    I:\Softys\java\javademos>cd\

    I:\>javac test.java

    I:\>java test
    Error: Could not find or load main class test

    I:\>

    I've also reinstalled the whole java1.6 more than 5 times by removing completely but this exception is appearing always.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: cmd prompt exception "could not find or load main class test.java"

    What is in the file: test.java?
    Did the compiling of test.java create a test.class file? Use the dir command to see what is in the folder with the test.java file.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Padmahasa (September 3rd, 2012)

  7. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    My Mood
    Happy
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile Re: cmd prompt exception "could not find or load main class test.java"

    Thank you again for suggesting me solution. I put that program with .java extension to one folder and compiled now its working fine. A lot of thank for you.

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. Replies: 8
    Last Post: August 9th, 2011, 08:25 PM
  3. Replies: 1
    Last Post: March 21st, 2011, 09:01 AM
  4. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM