簡體   English   中英

Java錯誤-Send不是抽象的,並且不會在Runnable中覆蓋抽象方法run()

[英]Java error - Send is not abstract and does not override abstract method run() in Runnable

當我嘗試編譯Java工作時出現以下錯誤。

Send.java:16: error: Send is not abstract and does not override abstract method run() in Runnable
public class Send implements Runnable {
       ^
1 error

我的Send.java代碼是

public class Send implements Runnable {

    private byte[] data = new byte[0];
    private String from = "";
    static DataOutputStream out = null;


    public Send(byte[] data, String from) throws IOException {
        data = data;
        from = from;

        out = Server.os;


        Log.logInfo("Data:" + DatatypeConverter.printHexBinary(data) + "");
        Log.logInfo("From:" + from + "");
        Log.logInfo("OS:" + out + "");




    }

}

用於在服務器文件中定義os輸出流的代碼是:

public class Server implements Runnable {

    private Socket socket;
    public static DataOutputStream os = null;
    private DataInputStream is = null;

    public Server(String originalHost) throws Exception {
        socket = new Socket(originalHost, 9339);

        Log.logInfo("* Connected to Server");
    }


    @Override
    public void run() {

        int bytes_read;
        try {

            DataInputStream is = new DataInputStream(socket.getInputStream());
            DataOutputStream os = new DataOutputStream(socket.getOutputStream());
....

我需要保留send.java代碼以使輸出流保持不變,因為不久之后它還將根據if語句從另一個文件中獲取相同的變量。

有沒有關於如何解決此問題的想法?

謝謝!

您可以使用Send類實現Runnable接口,但不要像在服務器類中那樣覆蓋run()方法。

在Send類中實現以下方法:

@Override
public void run() {}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM