错误!来自ObjectInputStream的readObject时线程中的java.io.EOFException

时间:2018-11-03 17:23:24

标签: java android

我在 Server Clain 之间输入了错误,这是Java Android Studio中的错误代码,当我输入用户名后登录时,此代码

public void signin() {
    try {
    data_socket dtsk = new data_socket();
    String[] data = new String[2];
    dtsk.action = "login";
    data[0] = textusername.getText().toString();
    data[1] = txtpassword.getText().toString();
    dtsk.data = data;

       dout = new ObjectOutputStream(Massenger_send.socket.getOutputStream());
        dout.writeObject(dtsk); System.out.println("=================================== After dout getOutputStream ");

    } catch (IOException ex) {
        java.util.logging.Logger.getLogger(Massenger_send.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

    }
}

这是data_socket类。

public class data_socket implements Serializable{
public String action ="afeef";
public String[] data;
public ArrayList<String[]> data_arr;
public ArrayList<friend> list_fr;
public boolean accept = false;
public data_socket(){

}

,当readObject中的ObjectInputStream出现此错误时,该错误出现在线程中:

public class receive  extends Thread{
public   Socket socket = null;
ObjectInputStream din = null;
data_socket respon = null ;
data_socket dtsk = new data_socket();

public receive(Socket skt) {
        this.socket=skt;

     }
@Override
public void run(){
    try {

        din = new ObjectInputStream(this.socket.getInputStream());
        while(true){

                respon=(data_socket)din.readObject();// her the error 

            switch(respon.action){
                case "login"             : this.check_login(); break;
                case "afeef"             : this.afeef();break;

                default                  : System.out.println("unknow action");
            }
        }
    } catch (IOException ex) {
        System.out.println("::::::::::::::::::ERROR 1::::::::::::::::"+ex.toString());
        System.out.println("lost connect ");
       System.exit(0);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();

    }
}

private void afeef() {

}


public void check_login(){
    if(respon.data[0].equalsIgnoreCase("true")){

        System.out.println(" the useranme and password is true and any thing like this is true no ");

    }
    else {
    }
}

此错误

  

11-03 12:15:22.443   9796-9796 / com.example.h.drawelayo W / EGL_emulation:eglSurfaceAttrib   未实现11-03 12:15:22.503 9796-9796 / com.example.h.drawelayo   D / OpenGLRenderer:启用调试模式0 11-03 12:15:26.793   9796-9796 / com.example.h.drawelayo I / Choreographer:跳过了248帧!   该应用程序可能在其主线程上做太多工作。 11-03   12:15:40.733 9796-9810 /? I / System.out :::::::::::::::::::: ERROR   1 ::::::::::::::::: java.io.EOFException 11-03 12:15:40.733 9796-9810 /?   I / System.out:您无法连接到服务器11-03 12:15:40.733   9796-9810 /? I / AndroidRuntime:VM退出,结果代码为0,正在清除   跳过

0 个答案:

没有答案