Réseau : java.lang.NullPointerException
Bonjour,
J'envoie ma classe Network (code ci-dessous) à ma classe viewTable depuis la classe client (où network est utilisée et marche très bien).
Ensuite ma classe viewTable va utilisé la classe Network mais il semblerait qu'elle ne soit pas instanciée.
Auriez-vous une idée ?
Erreur :
Citation:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at unoclient.Network.<init>(Network.java:30)
at unoclient.viewTable.<init>(viewTable.java:57)
at unoclient.viewTable$3.run(viewTable.java:184)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Classe network :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package unoclient;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
/**
*
* @author dafflone
*/
public class Network {
private Socket skt;
private ObjectOutputStream out;
private ObjectInputStream in;
public Network(Socket skt2) throws IOException{
skt = skt2;
}
public Network(Network net){
skt = net.getSocket(); <-------------- Erreur
out = net.getOut();
in = net.getIn();
}
public void writeObject(Object object) throws java.io.IOException{
System.out.println(" socket :"+skt.getInetAddress().getHostAddress());
if(out == null){
out = new ObjectOutputStream(skt.getOutputStream());
}
out.writeObject(object);
System.out.print("Packet sent : "+object.getClass()+" - to "+ skt.getInetAddress() +"\n");
out.flush();
}
public Object readObject() throws java.io.IOException, ClassNotFoundException{
if(in == null){
in = new ObjectInputStream(skt.getInputStream());
}
Object object = in.readObject();
System.out.print("Packet receive : "+object+" - from "+ skt.getInetAddress() +"\n");
return object;
}
/* Close the streams and the connection */
public void closeConnection(){
try {
this.in.close();
this.out.close();
this.skt.close();
} catch (IOException ex) {
Logger.getLogger(Network.class.getName()).log(Level.SEVERE, null, ex);
}
}
private Socket getSocket(){
return skt;
}
private ObjectOutputStream getOut(){
return out;
}
private ObjectInputStream getIn(){
return in;
}
} |
Méthode ou se trouve l'erreur(la ligne ou la méthode writeObject de network est utilisé) :
Code:
skt = net.getSocket();
Cordialement,
rXp>!<