我会将对象etudient从服务器java发送到客户端android
我使用ObjectOutputStream
在服务器中我从数据库获取etudient数据,然后将其发送到客户端android 服务器端:
while(rt.next()){
us1=new etudtoandroid(rt.getString("matricule"),rt.getString("nom"),rt.getString("prenom"));
System.out.println("object remplie");
out.writeObject(us1);
out.flush();
out.close();
System.out.println("object envoye");
userliste.add(us1);
}
clientSocket.close();
}
catch (IOException e) {
System.out.println("Could not listen on port: 4444");
e.printStackTrace();
return;
} catch (SQLException ex) {
System.out.println("tttttt: 4444");
} }
客户端android端: 我从服务器接收日期,然后反序列化为etudient类
try {
socket = new Socket("192.168.1.3", 4444);
Log.e("SOMETAG","connection etabluie");
ois = new ObjectInputStream(socket.getInputStream());
Log.d("dd", String.valueOf(b));
Log.e("SOMETAG","objr recu");
etudient gson =(etudient)ois.readObject();
Log.d("SOMETAG",gson.gematricule()+gson.getnom()+gson.getprenom());
} catch (IOException e) {
e.printStackTrace();
}
Log.e("SOMETAG","problem");
ois.close();
// textView.setText("object recu "+revoke.toString());
Log.e("SOMETAG","problem1");
} catch (UnknownHostException e1) {
Log.e("SOMETAG","erreu1");
} catch (IOException e1) {
Log.e("SOMETAG","erreu2");
} catch (ClassNotFoundException e1) {
Log.d("e1","erreu3");
}
return null;
}
}
class etudient:
public class etudient implements Serializable {
private static final long serialVersionUID = 1L; // Your version number
private String matricule1;
private String nom1;
private String prenom1;
public etudient(String matricule, String nom,String prenom) {
matricule1=matricule;
nom1=nom;
prenom1=prenom;
}
public String gematricule() {
return matricule1;
}
public String getnom(){
return nom1;
}
public String getprenom(){
return prenom1;
}
@Override
public String toString() {
return "RevockedUser{" +
"userIds='" + matricule1+ '\'' +
", listNumber=" + nom1 +
", counter=" + prenom1 +
'}';
}
}
输出:
在Android客户端中的错误 在erreu3中的例外
etudient gson =(etudient)ois.readObject();