I have two classes ChatClient
and Listener
and want to comile and run them. In eclipse it works fine, but on terminal I can't get it run. Both classes are on the path: /Desktop/java/task4
. Maybe I should mention that inside the ChatClient
class a Listener
Object gets created.
I compile the two classes with the command: javac *.java
and get 2 classes created. But if I type java ChatClient
I get the error main class could not be found or loaded
. What am I doing wrong? I'm using Ubuntu. And yes there is a main
method inside ChatClient
public class Listen extends Thread {
Socket s;
Scanner msg;
public Listen(Socket s) {
....
}
public class Chatter {
public static void main(String[] args) {
try {
...
Listener lt = new Listener(s);
...
}
There are many possibilities are there to get this error, while running from cmd. Because IDE will do many things related to class path in back ground.
Highest possibility of getting this error is, beginners will not aware of giving the full package structure while running using `java cmd` from correct classpath directory. Please go to this link for more information.
The obvious problem is that you class is in a package ( UE3
) but you have not used the full qualified class name. Try:
java UE3.ChatClient
There are many other possible problems, such as the classpath not being setup correctly.
(Note the convention for package names is all lowercase. Also rather than extending Thread
you should typically pass in a Runnable
as a lambda or method reference.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.