blackphoenix2 (Normal User)
Newbie
Messaggi: 2
Iscritto: 20/12/2009
|
Non riesco a capire l'errore, mi solleva un eccezione a client.add();
(il programma è incompleto lo so, per il momento crea solo la connessione).
Se potete date un occhiata ed aiutatemi, grazie mille in anticipo, ciao!
Codice sorgente - presumibilmente Java |
public class Server extends Thread{ private Utenti client; } public void connessione () throws IOException, ChatException { socket=server.accept(); Utente nuovo = new Utente(socket,""); try{ client.add(nuovo); } catch(ChatException e){ } str=nuovo.getReceive().readLine(); } Server s = new Server(); s.connessione(); } } public class Utenti { public Utenti() { } public boolean isPresent (String nickname ){ if(!(utenti.isEmpty())) Utente temp; while(it.hasNext()) { temp=(Utente)it.next(); if(nickname.equals(temp.getNickname())) return true; } } return false; } public void add(Utente utente)throws ChatException { if(!(isPresent(utente.getNickname()))) { if(utente.getNickname()=="") utente.setNickname("Guest"+utenti.size()… utenti.add(utente); } else throw new ChatException(); } public void remove (String nickname ) throws ChatException { Utente temp; if((!(utenti.isEmpty()))&&(isPresent(nic… { for(int i=0;i<utenti.size();i++){ temp=(Utente)utenti.elementAt(i); if(temp.getNickname().equals(nickname)); { utenti.removeElementAt(i); utenti.trimToSize(); } } }else throw new ChatException(); } } public class Client { public Client (String nickname ) { this.nickname = nickname; try { socket = new Socket("127.0.0.1", 1000 );send.print(nickname); System. out. println("Connesso"); } } } Client c = new Client("pippo"); } }
|
|