K
K
kungermu2021-11-12 14:39:13
Java
kungermu, 2021-11-12 14:39:13

Main does not see other classes. What to add?

I ran into a problem while writing the program.

I created the Main class, set the actions I needed, created the Jsoner class, did everything the same way, vscode does not swear.
618e5168d3765542917052.png

I ran the command: java -cp "$(printf %s: lib/*.jar)" ./src/don't care/Main.java
And got a response from java:
./src/don't care/Main.java:19: error: cannot find symbol
import whatever.Jsoner;
^
symbol: class Jsoner
location: package don't care ./src/don't care
/Main.java:27: error: cannot find symbol
Jsoner jsoner = new Jsoner();
^
symbol: class Jsoner
location: class Main
./src/don't care/Main.java:27: error: cannot find symbol
Jsoner jsoner = new Jsoner();
^
symbol: class Jsoner
location: class Main
3 errors
error: compilation failed

Contents Main:
import don't care.Jsoner;
public class Main {
public static void main(String[] string) {
Jsoner jsoner = new Jsoner();
jsoner.sendMsg();
}
}

Jsoner content:
public class Jsoner {
public static void sendMsg() {
System.out.println("ok");
}
}

truncated the extra code in Main intentionally, I think you are not particularly interested in the rest of the code, it should not cause this error.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TheAndrey7, 2021-11-12
@TheAndrey7

It is very interesting how you are going to run the source code? They must first be compiled into classes with the javac command . In order not to compile everything manually, use the Gradle build system .

O
Orkhan, 2021-11-12
Hasanly @azerphoenix

Good afternoon.
Well, first of all, why call a static method sendMsg()through an instance of the Jsoner class? You can access the method directly via Jsoner.sendMsg()
Second,
location: package неважно
Important. Since the package name must comply with the naming convention. I recommend opening this project in Intellij IDEA and most likely it will swear. It is possible that the directory name contains invalid characters (such as dashes or hyphens).
Thirdly,

java -cp "$(printf %s: lib/*.jar)" ./src/неважно/Main.java

Here is the answer to your question - https://stackoverflow.com/questions/219585/includi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question