Results 1 to 6 of 6
  1. #1
    doomking517 is offline Member
    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0

    Default could not find or load main class calc.Calc

    well I tried using java -jar "C:\Users\******\Documents\NetBeansProjects\Calc\d ist\calc.jar" and the file wont run and gives the error "could not find or load main class calc.Calc"

    the source for the application (if needed is):
    Java Code:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    public class Calc {
    
        public static void main(String[] args) throws IOException {
            int a;
            int b;
            String sum;
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            a = br.read();
            BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
            b = br1.read();
            BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
            sum = br2.readLine();
            if ("+".equals(sum))
            {
                int c = a + b;
                System.out.println(a + "+" + b + "=" + c);
            }
            if ("-".equals(sum))
                {
                int c = a - b;
                System.out.println(a + "-" + b + "=" + c);
                }
            if ("/".equals(sum))
                {
                int c = a / b;
                System.out.println(a + "/" + b + "=" + c);
                }
            if ("*".equals(sum))
                {
                int c = a * b;
                System.out.println(a + "*" + b + "=" + c);
                }
            
                
            }
            
            
        }
    and im wondering why the code wont load (as it compiled fine so im rather confused), does anyone have any suggestions?

    p.s. this is my first time writting in java but i have looked at a few posts although nothing seemed to help (i.e. i tried using java -cp -jar)

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,383
    Rep Power
    5

    Default Re: could not find or load main class calc.Calc

    You need to include the main entry point within the manifest of the Jar file. Check out Running JAR-Packaged Software (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    doomking517 is offline Member
    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0

    Default Re: could not find or load main class calc.Calc

    my manifest file contains

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.8.4
    Created-By: 1.7.0_21-b11
    Class-Path:
    X-COMMENT: Main-Class will be added automatically by build
    Main-Class: calc.Calc

    which i presume is correct


    Edit:
    figured it out... the calc.Calc wasn't part of the .jar (it some how happened to be in another project), not quite sure but oh well, its working now, thanks for the help though
    Last edited by doomking517; 06-12-2013 at 01:56 PM.

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,383
    Rep Power
    5

    Default Re: could not find or load main class calc.Calc

    Your manifest says you have a package of calc. But there is no package declaration in your code.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    doomking517 is offline Member
    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0

    Default Re: could not find or load main class calc.Calc

    yeah, i started a new project with the same code (but with out editing the stuff at the top) and tried it and then noticed i was missing that part, anyway i edited the code (because i was getting a series of errors) and now i have it working but if someone enters a character not a number it crashes how would you avoid that? (i understand i shoudl start a new topic but i would like to avoid cluttering the forums.)

    the code i have is:
    Java Code:
    package Calc1;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Scanner;
    
    public class Calc1 {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws IOException {
            // TODO code application logic here
            Scanner in = new Scanner(System.in);
            Scanner in2 = new Scanner(System.in);
            int a = 0;
            int b = 0;
            String sum;
            System.out.println("Please enter the first number you wish to calculate.");
            a = in.nextInt();
            System.out.println("Please enter the second number you wish to calculate.");
            b = in2.nextInt();
            BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Please enter the operator you wish to calculate with.");
            sum = br2.readLine();
            if ("+".equals(sum))
            {
                int c = a + b;
                System.out.println(a + "+" + b + "=" + c);
            }
            if ("-".equals(sum))
                {
                int c = a - b;
                System.out.println(a + "-" + b + "=" + c);
                }
            if ("/".equals(sum))
                {
                int c = a / b;
                System.out.println(a + "/" + b + "=" + c);
                }
            if("*".equals(sum))
                {
                int c = a * b;
                System.out.println(a + "*" + b + "=" + c);
                }
            else {
                System.out.println("please enter one of the following + - / * for this application to work succesfully");
            }
            
        }
        
    }
    what would you suggest to stop it crashing if they enter a char?

    Edit:
    figured this out as well
    Last edited by doomking517; 06-12-2013 at 02:59 PM.

  6. #6
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,383
    Rep Power
    5

    Default Re: could not find or load main class calc.Calc

    Quote Originally Posted by doomking517 View Post
    (i understand i should start a new topic but i would like to avoid cluttering the forums.)
    It would probably be better to start a new thread. Otherwise, someone may do a title/subject search on a problem not realizing their solution is within the body of an unrelated thread. This is also why title/subject wording is so important. And in the future, please include your discovered solution so others may benefit.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 1
    Last Post: 11-29-2012, 09:46 AM
  2. Could not find or load main class
    By kkid in forum New To Java
    Replies: 4
    Last Post: 10-15-2012, 04:47 AM
  3. Error: Could not find or load main class
    By Tybald in forum Eclipse
    Replies: 5
    Last Post: 05-28-2012, 11:22 AM
  4. need help postfix calc
    By b3222 in forum Advanced Java
    Replies: 1
    Last Post: 03-12-2012, 11:05 PM
  5. Investment Calc
    By rfore1 in forum New To Java
    Replies: 13
    Last Post: 02-28-2010, 06:21 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
  •