Results 1 to 11 of 11
  1. #1
    Tejeshwar is offline Member
    Join Date
    Apr 2016
    Posts
    2
    Rep Power
    0

    Post error, could not find or load main class!!!

    I am unable to execute this programme below




    import java.util.*;
    class A
    {
    int a;

    void input1()
    {
    Scanner s=new Scanner(System.in);
    System.out.println("enter a==");
    a=s.nextInt();
    }

    }
    class B extends A
    {
    int b;

    void input2()
    {

    Scanner s1=new Scanner(System.in);
    System.out.println("enter b==");
    b=s1.nextInt();
    }

    }

    class C extends B
    {


    void input3()
    {
    System.out.println("a=="+a);
    System.out.println("b=="+b);
    System.out.println("ans=="+a*b);
    }
    public static void main(String args[])
    {

    C obj = new C();

    obj.input1();
    obj.input2();
    obj.input3();

    }
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: error, could not find or load main class!!!

    There is no public static void main(String[] args) method in your class. The Java runtime does not know where to start.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: error, could not find or load main class!!!

    Yes there is, or am I misreading this?
    Java Code:
    public static void main(String args[])
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: error, could not find or load main class!!!

    To answer this more info is required. Specifically, how did you invoke the program (what class was the target of the java command)?
    And please use BB Code List - Java Programming Forum - Learn Java Programming to format your code. I have done it for you here.

    Java Code:
    import java.util.*;
    
    class A {
       int a;
    
       void input1() {
          Scanner s = new Scanner(System.in);
          System.out.println("enter a==");
          a = s.nextInt();
       }
    
    }
    
    class B extends A {
       int b;
       void input2() {
          Scanner s1 = new Scanner(System.in);
          System.out.println("enter b==");
          b = s1.nextInt();
       }
    }
    
    class C extends B {
       void input3() {
          System.out.println("a==" + a);
          System.out.println("b==" + b);
          System.out.println("ans==" + a * b);
       }
       public static void main(String args[]) {
          C obj = new C();
    
          obj.input1();
          obj.input2();
          obj.input3();
       }
    }
    Regards,
    Jim
    Last edited by jim829; 04-05-2016 at 03:14 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: error, could not find or load main class!!!

    Quote Originally Posted by Tolls View Post
    Yes there is, or am I misreading this?
    Java Code:
    public static void main(String args[])
    Oh crap. *puts on the glasses and looks again*. Probably the wrong class on the commandline then :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    Sizzlewump's Avatar
    Sizzlewump is offline Member
    Join Date
    Oct 2010
    Location
    MI, USA
    Posts
    68
    Rep Power
    0

    Default Re: error, could not find or load main class!!!

    I think you need to change line 29 to say:
    Java Code:
     public static void main(String[] args) {
    instead of:
    Java Code:
     public static void main(String args[]) {
    "The secret to getting what you want is to reject everything that you don't want." -Wolbers

  7. #7
    Sizzlewump's Avatar
    Sizzlewump is offline Member
    Join Date
    Oct 2010
    Location
    MI, USA
    Posts
    68
    Rep Power
    0

    Default Re: error, could not find or load main class!!!

    Also, I believe it's good practice to close your scanner objects when you're finished with them. So try s.close() and s1.close() at the end of their respective methods unless you plan to invoke them later in the code.
    "The secret to getting what you want is to reject everything that you don't want." -Wolbers

  8. #8
    Pavlo is offline Member
    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0

    Default Re: error, could not find or load main class!!!

    Hello

    First I would try to run from IDE (Eclipse, Netbeans ...). It very helpful to find errors in your code. After all works from IDE - try to export to runnable jar file and start like java -jar yourApp.jar

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: error, could not find or load main class!!!

    Actually, both forms are acceptable syntax.

    Regards,
    Jim
    Last edited by jim829; 04-11-2016 at 04:37 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: error, could not find or load main class!!!

    Quote Originally Posted by Pavlo View Post
    First I would try to run from IDE (Eclipse, Netbeans ...). It very helpful to find errors in your code. After all works from IDE - try to export to runnable jar file and start like java -jar yourApp.jar
    Better to try and debug it without an IDE (before getting addicted to one).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  11. #11
    Pavlo is offline Member
    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0

    Default Re: error, could not find or load main class!!!

    Yes you right:

    Better to try and debug it without an IDE (before getting addicted to one).
    It better in sense of study :)

Similar Threads

  1. Error: Could not find or load main class
    By Georgie23 in forum Eclipse
    Replies: 32
    Last Post: 10-30-2014, 10:44 AM
  2. 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
  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 Tybald in forum Eclipse
    Replies: 5
    Last Post: 05-28-2012, 11:22 AM
  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
  •