0

I have the following java file in C:\projects\com.company folder:

package com.company;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Logger;

import weka.classifiers.Classifier;
import weka.classifiers.evaluation.Evaluation;
import weka.classifiers.functions.MultilayerPerceptron;
import weka.core.Instances;

public class MyProgram {

    public static void main(String[] args) {
        //want to check the args parameters
    }
}

Then I try to run the following command in C:\projects directory:

java com.company.MyProgram C:\inputs\test.txt pro2 pro3

Then expect to get 3 parameters in the main method's args. However gives, "Error: Could not find or load main class com.company.MyProgram" error.

So, the questions:

1. What is the problem with this code or command?

2. How can I debug this code using IntelliJ and check the args after running java com.company.MyProgram C:\inputs\test.txt pro2 pro3 command on cmd?

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • Have you tried to compile the Java file again? The current compiled file might be an older one which doesn't have a `main` method. – enzo May 18 '21 at 19:16
  • Do you mean build and then using the `out\production\...` directory? –  May 18 '21 at 19:20
  • @CrazyCoder Do you have any idea? –  May 18 '21 at 19:20
  • Yes, see if it works. I tried this code using an online Java compiler and it's working fine, maybe it's something related to compiling and stuff. – enzo May 18 '21 at 19:23
  • What about debug via cmd? –  May 18 '21 at 19:26
  • If you want to debug using Intellij, you can [add the command-line arguments](https://stackoverflow.com/q/2066307/9997212) and [debug normally](https://www.jetbrains.com/help/idea/debugging-code.html#general-procedure): it'll show the value of each argument inside the `args`. If you want to debug using the command-line, you can add [some command-line arguments](https://stackoverflow.com/q/138511/9997212) when running `java`. – enzo May 18 '21 at 19:36
  • 1. It could be because your folder structure should be "C:\projects\com\company" and not "C:\projects\com.company". 2. You have not compiled your source and the .class file is missing in that folder. – Srikanth Chakravarthy May 18 '21 at 20:45

0 Answers0