Eclipse 要求我对此进行抽象?

Eclipse asking me to make this abstract?

我需要生成两个单独的 jar 文件,它们相互交互但做不同的事情。我将两个项目加载到 Eclipse 中,但都使用了很多相同的导入,因此我将它们放在同一工作区下的子文件夹中。

当我尝试 运行 时,其中一个 "java class xxxx 无法找到”。

当我试图解决这个问题时,我比较了这两个项目并注意到一个文件夹是工作项目的外部构建路径的一部分,而不是非工作项目的外部构建路径的一部分。我把它加到不能用的那把能用的弄坏了。

现在一直在工作的那个在 class 主名称上有一个错误。我调用程序 ZSTATEEngine,所以 class 是

public class ZSTATEngine implements ETOSFilterEngine 

现在该名称已突出显示,当我将鼠标悬停在其上时显示:"the type ZSTATEngine 必须实现继承的抽象方法 ETOSFilterEngine.doFilter(MessageBlock)"

有什么可以改变的?之前它工作正常,代码本身没有任何变化。我不明白引用的库是如何工作的,但至少在以前工作的项目中它们的结构看起来没有任何变化。

好的,一些进一步的信息:我确实在其中有一个部分 class:

public MessageBlock doFilter(MessageBlock msgBlock)

所以我正在实施该方法...但是该方法现在内部有错误,

"The method addFilteredMessage(MessageBlock) in the type FilterFramework is not applicable or the arguments (MessageBlock) ...

怎么会变坏?它也工作正常。

完整代码如下:

package com.ibm.tpf.internal;

import java.awt.Color;  
/*import java.util.ArrayList;*/
/*import java.util.*;*/

import com.ibm.tpf.etos.TPFFilter.*;
//import com.ibm.tpf.etos.TPFFilter.TernarySwitch;

import com.ibm.tpf.etos.api.*;
/*
import com.ibm.tpf.etos.api.Constants;
import com.ibm.tpf.etos.api.MessageBlock;
*/
import com.ibm.tpf.etos.filter.*;
/*
import com.ibm.tpf.etos.filter.ETOSFilterEngine;
import com.ibm.tpf.etos.filter.FilterConfigurationException;
import com.ibm.tpf.etos.filter.FilterFramework;
import com.ibm.tpf.etos.filter.FilterRuntimeException;
*/

public class ZSTATEngine implements ETOSFilterEngine {
    FilterFramework fw = null;
    String[] names = null;

    public ZSTATEngine(FilterFramework filFW, String[] parms) {
        super();
        this.fw = filFW;
    }

    /* AAES0009I 13.45.01 FROM TA 05 : AUTC0000I TOSFCOLOR_GREEN TOSBCOLOR_NONE TOSHOLD_0 TOSSAVE_0 TOSALERT_0 AUTC1111I 12.04.41 OK */
    public MessageBlock doFilter(MessageBlock msgBlock) throws FilterRuntimeException {
        if(msgBlock.getMsgID().equals("AAES0009I")) { /* only handle messages that start with AAES0009I */
            if(msgBlock.getMsg().indexOf("ZUVRT") != -1) { /* if the message contains "ZUVRT" then let it through.  We want to react to the result of it, not the ZUVRT itself. */
                return msgBlock;
            }
            if(msgBlock.getMsg().indexOf("AUTC0000I") != -1) {        /* search string to see if "AUTC0000I is in it.  If it is then do..." */ 
                String myString = msgBlock.getMsg();
                Color fColor = Color.WHITE;                           /* set default colors */
                Color bColor = Color.BLACK;
                msgBlock.setSuppressed(TernarySwitch.ON);             /* suppress original message to display new one */
                String[] myStringParts = myString.split("\s+",13);   /* divide message into 13 parts.  The 13th part is everything remaining. */
                String finalPart = myStringParts[12].toString();      /* print last part to the screen */
                MessageBlock mb = new MessageBlock(finalPart, Constants.ETOS_ONE_MSG);
                String fColorMsg     = myStringParts[7].toString();   /* Process the foreground color portion */
                if (!fColorMsg.contains("NONE")) {
                    fColor = ColorStringInterpreter(fColorMsg);
                    mb.setForeground(fColor);
                }
                String bColorMsg     = myStringParts[8].toString();   /* Process the background color portion */
                if (!bColorMsg.contains("NONE")) {
                    bColor = ColorStringInterpreter(bColorMsg);
                    mb.setBackground(bColor);
                }
                String holdMsg = myStringParts[9].toString();         /* Process the hold message portion */
                if (holdMsg.toUpperCase().startsWith("TOS")) {        /* if it starts with TOS, grab only the number at the end */
                    String[] holdPart = holdMsg.split("_",2);
                    if (holdPart[1].toString().equals("1")) {
                        mb.setHeld(TernarySwitch.ON);   
                    }   
                }
                else {
                    if (holdMsg.equals("1")) {                        /* otherwise, just use the number */
                        mb.setHeld(TernarySwitch.ON);   
                    }
                }
                String saveMsg = myStringParts[10].toString();        /* Process the save areas.  These have two formats currently: TOSSAVE_X_X_X_X and BBBBBBBBB, where X is a digit 1-32, and B is binary. */
                if (saveMsg.toUpperCase().startsWith("TOS")) {         
                    String[] savePart = saveMsg.split("_");           /* handle the multiple digit save areas, and ignore the first split which is TOSSAVE */
                    if (!savePart[1].toString().equals("0")) {
                        long areaBits = 0;
                        for (int i=1; i<savePart.length; i++) {
                            areaBits |= 1L << Integer.parseInt(savePart[i]);
                        }   
                        mb.setSave(areaBits);
                    }
                }
                else {                                               /* otherwise, just use the binary string directly */
                    long areaBits = Long.parseLong(myStringParts[10].toString(), 2);
                    mb.setSave(areaBits);
                }
                fw.addFilteredMessage(mb);                           /* this is the command that pieces the whole message together */
            }
        }
        int plusLocation = msgBlock.getMsg().lastIndexOf('+');
        if (plusLocation > 0) {
            MessageBlock mb1 = new MessageBlock(msgBlock.getMsg(), msgBlock.getFlag());
            fw.addFilteredMessage(mb1);
            msgBlock.setSuppressed(TernarySwitch.ON);
            MessageBlock mb2 = new MessageBlock("", Constants.ETOS_ONE_MSG);
            fw.addFilteredMessage(mb2);
        }
        return msgBlock;                                             /* whatever gets returned is what the system prints */
    }

    private Color ColorStringInterpreter(String colorMsg) throws FilterRuntimeException {
        if (colorMsg.toUpperCase().startsWith("TOS")) {              /* if it starts with TOS, then we're using color names */
            String[] colorParts = colorMsg.split("_",2);
            String colorTxt     = colorParts[1].toString().trim();
            if (colorTxt.toUpperCase() != "NONE") {
                Color finalColor = Colors.fromString(colorTxt);
                return finalColor;
            }
        }
        else {
            String[] colorParts = colorMsg.split("_",3);            /* otherwise we're using RGB values */
            String sRed = colorParts[0].toString().trim();
            String sGreen = colorParts[1].toString().trim();
            String sBlue = colorParts[2].toString().trim();
            /*mb = new MessageBlock(sRed, Constants.ETOS_ONE_MSG);*/
            int iRed = Integer.parseInt(sRed);
            int iGreen = Integer.parseInt(sGreen);
            int iBlue = Integer.parseInt(sBlue);
            Color finalColor = new Color (iRed, iGreen, iBlue);
            return finalColor;
        }
        return null;
    }

    public String getName() {
        return null;
    }

    public void modifyState(Object[] newParams) throws FilterConfigurationException, FilterRuntimeException {
    }

    public boolean isActive() {
        return false;
    }

    public void shutdown() {
    }
}
public class ZSTATEngine implements ETOSFilterEngine

根据上面的代码,您的class ZSTATEEngine正在实现一个接口ETOSFilterEngine,这意味着您的class需要实现ETOSFilterEngine的所有抽象方法。

来自 Java doc

Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.

勾选 link: http://www-01.ibm.com/support/knowledgecenter/SSB23S_1.1.0.9/com.ibm.tpfops.doc_1112/aaeo1/fengapi.html?cp=SSB23S_1.1.0.9%2F2-3-10-3

以下是 ETOSFilterEngine 中存在的 5 个方法,您需要实现这些方法。

public MessageBlock doFilter (MessageBlock) throws
          FilterRuntimeException;
     public void modifyState (Object[ ]) throws
          FilterConfigurationException,
          FilterRuntimeException;
     public boolean isActive();
     public void shutdown();
     public String getName();

上面link有一个关于如何正确实现这个接口的代码示例。您可以看到示例中的 class ZSTATEEngine 正在实现 ETOSFilterEngine 提供的所有 5 个方法。

Check the type of MessageBlock in your imports, it should be import com.ibm.tpf.etos.api.MessageBlock; I can see that you have commented your import which is wrong.

Uncomment the line : import com.ibm.tpf.etos.api.MessageBlock;

如 "Jakub Zaverka" 所述,您可能在 class 路径或构建路径中有两个版本。查看jar的顺序,是否选对了class...即使代码没改也会出现。

找到它的一种方法是,只需在 ETOSFilterEngine 上按 F3,然后单击程序包资源管理器中的 "Link with editor" 选项。它将显示 .class 文件和从中拾取它的 jar。如果它来自错误的 jar 或旧 jar,只需转到项目>属性>构建路径>顺序和导出并更改顺序通过单击“顶部”按钮将右侧的 jar 移至顶部..