Error: Could not find or load main class Mainex1"

Asked

Viewed 793 times

0

Previously questioned question that gave basis to this error

The error in question is the use of a JAVA program using the Linux Terminal.

I already have the compiled classes, the error appears when I try to run those same previously compiled classes:

Print Erro:

      zeluis@zeluis-HP-EliteBook-8460p ~/NetBeansProjects/SOCP1/src/socp1 $ ls
      CalculatorMethodos.java  MainEX1.class  MainEX1.java
      zeluis@zeluis-HP-EliteBook-8460p ~/NetBeansProjects/SOCP1/src/socp1 $ java MainEX1
      Error: Could not find or load main class MainEX1

Code Mainex1 class

    package socp1;

import java.io.IOException;
import java.util.Scanner;


/**
 *
 * @author zeluis
 */
public class MainEX1 {

    /**
     * @param args the command line arguments if a number is not enter, the
     * system take the value as 0.
     */
    public static void main(String[] args) throws IOException {

        //EXERCICIO1
     /*   int num1, num2, total = 0, opcCalc, vef = -1;
        CalculatorMethodos cM = new CalculatorMethodos();
      //read from keyboard
        Scanner lerDataKeyBoard = new Scanner(System.in);
        // BufferedReader lerDataKeyBoard = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("First number:\n");
        num1 = lerDataKeyBoard.nextInt();
        System.out.println("Second number:\n");
        num2 = lerDataKeyBoard.nextInt();

        System.out.println("Introduza a operação:\n");
        System.out.println("'1' - SUM\n");
        System.out.println("'2' - SUBTRACT\n");
        System.out.println("'3' - MULTIPLY\n");
        System.out.println("'4' - DIVIDE\n");

        opcCalc = lerDataKeyBoard.nextInt();

        switch (opcCalc) {
            case 1:
                total = cM.add(num1, num2);
                break;
            case 2:
                total = cM.sub(num1, num2);
                break;
            case 3:
                total = cM.sub(num1, num2);
                break;
            case 4:
                total = cM.div(num1, num2);
                break;
        }
        System.out.println("Resultado:" + total); */

     //EXERCICIO 2
       int num1, num2, total = 0, opcCalc, vef = -1;
       // CalculatorMethodos cM = new CalculatorMethodos();
      //read from keyboard
        Scanner lerDataKeyBoard = new Scanner(System.in);
        // BufferedReader lerDataKeyBoard = new BufferedReader(new InputStreamReader(System.in));
    /*    System.out.println("First number:\n");
        num1 = lerDataKeyBoard.nextInt();
        System.out.println("Second number:\n");
        num2 = lerDataKeyBoard.nextInt(); */


        System.out.println("Introduza a operação:\n");
        System.out.println("'1' - SUM\n");
        System.out.println("'2' - SUBTRACT\n");
        System.out.println("'3' - MULTIPLY\n");
        System.out.println("'4' - DIVIDE\n");

        opcCalc = lerDataKeyBoard.nextInt();

        switch (opcCalc) {
            case 1:
              //  total = cM.add(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
                break;
            case 2:
              // total = cM.sub(args[0], args[1]);
                break;
            case 3:
             //   total = cM.sub(args[0], args[1]);
                break;
            case 4:
               // total = cM.div(args[0], args[1]);
                break;
        }
        System.out.println("Resultado:" + total);

    }

    }
  • Add the link from the previous question to give context and put the final code to make it clearer to those who didn’t see the other question

  • 1

    Seems duplicate to me

  • 1

    I was going to answer, but in fact, it’s the same mistake

  • 1

    It can run here, the problem is in the way you executes

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.