저는 대학에서 간단한 채팅을해야합니다. NetBeans에서 실행하려고하면 "주 수업을 찾을 수 없습니다"라고 표시됩니다. 나는 이해하지 못한다. 나는 주 수업을 가지고 있다고 믿는다. 그래서 누군가가 문제가있는 곳을 말해 줄 수 있을까? 코드는 다음과 같습니다.메인 클래스가 없습니다?
import java.io.* ;
import java.net.*;
public class server {
private static ServerSocket socketservidor = null;
private static Socket socketcliente = null;
private static final int maxclientes = 4;
private static final clienteThread[] hilos = new clienteThread[maxclientes];
public static void main(String args[]) {
int puerto = 2222;
if (args.length < 1) {
System.out.println("CONEXION REALIZADA CORRECTAMENTE \n"
+ "CHAT INICIADO CORRECTAMENTE \n" + "NUM. PUERTO="
+ puerto);
} else {
puerto = Integer.valueOf(args[0]).intValue();
}
try {
socketservidor = new ServerSocket(puerto);
} catch (IOException e) {
System.out.println(e);
}
while (true) {
try {
socketcliente = socketservidor.accept();
int i = 0;
for (i = 0; i < maxclientes; i++) {
if (hilos[i] == null) {
(hilos[i] = new clienteThread(socketcliente, hilos))
.start();
break;
}
}
if (i == maxclientes) {
PrintStream oc = new PrintStream(
socketcliente.getOutputStream());
oc.println("Servidor ocupado. Vuelve a intentar más tarde");
oc.close();
socketcliente.close();
}
} catch (IOException e) {
System.out.println(e);
}
}
}
}
class clienteThread extends Thread {
private PrintStream salida = null;
private DataInputStream entrada = null;
private int maxclientes;
private final clienteThread[] threads;
private Socket socketcliente = null;
public clienteThread(Socket socketcliente, clienteThread[] threads) {
this.socketcliente = socketcliente;
this.threads = threads;
maxclientes = threads.length;
}
public void run() {
int maxclientes = this.maxclientes;
clienteThread[] threads = this.threads;
try {
entrada = new DataInputStream(socketcliente.getInputStream());
salida = new PrintStream(socketcliente.getOutputStream());
salida.println("Solo nos falta saber tu nombre para empezar:");
String nombre = entrada.readLine().trim();
salida.println("Bienvenido a nuestro chat " + nombre + "\n"
+ "Ya puedes chatear con otros usuarios!" + "\n"
+ " teclea /salir para abandonar chat");
for (int i = 0; i < maxclientes; i++) {
if (threads[i] != null && threads[i] != this) {
threads[i].salida.println("***" + nombre
+ " se ha conectado!!!***");
}
}
while (true) {
String linea = entrada.readLine();
if (linea.startsWith("/salir")) {
break;
}
for (int i = 0; i < maxclientes; i++) {
if (threads[i] != null && threads[i] != this) {
threads[i].salida.println(">>" + nombre + ":" + linea);
}
if (threads[i] != null && threads[i] == this) {
threads[i].salida.println("YO:" + linea);
}
}
}
for (int i = 0; i < maxclientes; i++) {
if (threads[i] != null && threads[i] != this) {
threads[i].salida.println("***" + nombre
+ " se ha desconectado***");
}
}
salida.println("***Te has desconectado del chat***");
for (int i = 0; i < maxclientes; i++) {
if (threads[i] == this) {
threads[i] = null;
}
}
entrada.close();
salida.close();
socketcliente.close();
} catch (IOException e) {
System.out.println(e);
}
}
}
간단한 프로그램으로 문제를 재현 해 보았습니까? – didierc
어떻게 실행하나요? 그리고 프로젝트를 만들었습니까? – longhua
IDE가 소스를 자동 컴파일하지 않을 수 있습니다. 이것은 귀하의 오류의 원인 일 수 있습니다. –