Results 1 to 5 of 5
  1. #1
    Javasubbu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Error: Could not find or load main class Ops.java

    Hi,

    I was able to compile it but no run this code. Where am I missing?
    Java Code:
    import java.util.Scanner;
    public class Ops{
    	public static void main(String[] args)
    	{
    	Scanner input =new Scanner(System.in);
    	int num = input.nextInt();
    	System.out.printf("Pre Increment %d\n", ++num);
    	System.out.printf("Post Increment %d\n", num++);
    	System.out.printf("Pre Decrement %d\n", --num);
    	System.out.printf("Post Decrement %d\n", num--);
    	}
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

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

    Error: Could not find or load main class Ops.java ....let me guess: You try to run it with "java Ops.java" instead of "java Ops" ? You will get a class file after compile.... :)

  3. #3
    Javasubbu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

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

    Thanks! Yes, I did this mistake...

  4. #4
    blurocket9 is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

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

    This is why Java drives me nuts. I used Netbeans its much faster. I got that same error over and over again I finally moved the class file to the JDK BIN directory and it finally executed. So what gives? What directory should I have the .JAVA file in ...I tried all of the recommendations: path, setting directory, ,.etc to no avail

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

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

    The compiler simply needs to know where the class file is located. If it's in your current directory, just use 'java . FileName'

Similar Threads

  1. Replies: 10
    Last Post: 02-02-2012, 08:26 PM
  2. Replies: 29
    Last Post: 02-02-2012, 08:23 PM
  3. 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
  4. Could not find or load main class BubbleSort.class
    By blaqkout in forum New To Java
    Replies: 5
    Last Post: 09-12-2011, 07:54 PM
  5. runtime error 'could not find main class' ?
    By ruud00000 in forum Java Applets
    Replies: 5
    Last Post: 12-31-2010, 05:58 PM

Posting Permissions

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