当前位置:编程学习 > wap >>

android 中运行到new ObjectInputStream(sock.getInputStream());就抛异常了

android 中运行到new ObjectInputStream(sock.getInputStream());就抛异常了
想用对象输入输出流 和服务之间交换信息,信息封装在problemDTO中了

这个是android端代码
  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
         DataOutputStream dos=new DataOutputStream(sock.getOutputStream());
         Log.i("sc","1");//控制台打印1,就抛异常跳到catch中去了
fromServer = new ObjectInputStream(sock.getInputStream());
Log.i("sc","2");
dos.writeInt(2);
Log.i("sc","3");
List<ProblemDTO> list=null;
list=(List<ProblemDTO>)fromServer.readObject();
Log.i("sc",list.size()+"");
}catch (Exception e1) {
e1.printStackTrace();
Log.i("sc","yc");
}
}


服务器端代码
ServerSocket sSocket = new ServerSocket(2011);
System.out.println("waiting a connection from the client");
Robot robot = new Robot();
Socket sock = sSocket.accept();
System.out.println("recv a connection");                                              
fromClient = new ObjectInputStream(sock.getInputStream());
fromServer = new ObjectOutputStream(sock.getOutputStream());
int result=1;
do{
result=fromClient.readInt();
fromServer.writeObject(ProblemDAO.GetAllNewProblems());
fromServer.flush();
                   }while(result!=1)

有没有大侠碰到过这样的问题,纠结1天了 --------------------编程问答-------------------- 我也是碰到这样的问题,求解!
补充:移动开发 ,  Android
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,