0

获取错误预验证类 java/langnoclassdeffounderror : java/lang/comparable for java me 平台。

我已将我的 J2SE 代码迁移到 J2ME 代码。我知道有些函数 J2SE 函数在 J2ME 平台上不起作用。因此,我已经对 Comparable 类进行了交叉检查。它包含在 Java ME 库中。

现在,我无法解决这些错误。请帮帮我。

请参考以下代码:

import java.io.Serializable;

import aiproject.CompareToBuilder;
import aiproject.EqualsBuilder;
import aiproject.HashCodeBuilder;
import aiproject.ToStringBuilder;


public class WordProbability implements Comparable, Serializable {


    private static final int UNDEFINED = -1;

    private String word = "";
    private String category = ICategorisedCategorizer.DEFAULT_CATEGORY;

    private long matchingCount = UNDEFINED;
    private long nonMatchingCount = UNDEFINED;

    private double probability = ICategorizer.NEUTRAL_PROBABILITY;

    public WordProbability() {
        setMatchingCount(0);
        setNonMatchingCount(0);
    }

    public WordProbability(String w) {
        setWord(w);
        setMatchingCount(0);
        setNonMatchingCount(0);
    }

    public WordProbability(String c, String w) {
        setCategory(c);
        setWord(w);
        setMatchingCount(0);
        setNonMatchingCount(0);
    }

    public WordProbability(String w, double probability) {
        setWord(w);
        setProbability(probability);
    }

    public WordProbability(String w, long matchingCount, long nonMatchingCount) {
        setWord(w);
        setMatchingCount(matchingCount);
        setNonMatchingCount(nonMatchingCount);
    }

    public void setWord(String w) {
        this.word = w;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public void setProbability(double probability) {
        this.probability = probability;
        this.matchingCount = UNDEFINED;
        this.nonMatchingCount = UNDEFINED;
    }

    public void setMatchingCount(long matchingCount) {
        if (matchingCount < 0) {
            throw new IllegalArgumentException("matchingCount must be greater than 0");
        }
        this.matchingCount = matchingCount;
        calculateProbability();
    }

    public void setNonMatchingCount(long nonMatchingCount) {
        if (nonMatchingCount < 0) {
            throw new IllegalArgumentException("nonMatchingCount must be greater than 0");
        }
        this.nonMatchingCount = nonMatchingCount;
        calculateProbability();
    }

    public void registerMatch() {
        if (matchingCount == Long.MAX_VALUE) {
            throw new UnsupportedOperationException("Long.MAX_VALUE reached, can't register more matches");
        }
        matchingCount++;
        calculateProbability();
    }

    public void registerNonMatch() {
        if (nonMatchingCount == Long.MAX_VALUE) {
            throw new UnsupportedOperationException("Long.MAX_VALUE reached, can't register more matches");
        }
        nonMatchingCount++;
        calculateProbability();
    }

    private void calculateProbability() {
       String method = "calculateProbability() ";
        double result = ICategorizer.NEUTRAL_PROBABILITY;
        if (matchingCount == 0) {
            if (nonMatchingCount == 0) {
                result = ICategorizer.NEUTRAL_PROBABILITY;
            } else {
                result = ICategorizer.LOWER_BOUND;
            }
        } else {
            result = BayesianCategorizer.normaliseSignificance((double) matchingCount / (double) (matchingCount + nonMatchingCount));
        }

        probability = result;
    }

    /**
     * output
     */
    public double getProbability() {
        return probability;
    }

    public long getMatchingCount() {

        if (matchingCount == UNDEFINED) {
            throw new UnsupportedOperationException("MatchingCount has not been defined");
        }

        return matchingCount;
    }

    public long getNonMatchingCount() {

        if (nonMatchingCount == UNDEFINED) {
            throw new UnsupportedOperationException("nonMatchingCount has not been defined");
        }

        return nonMatchingCount;
    }

    public String getWord() {
        return word;
    }

    public String getCategory() {
        return category;
    }

    public boolean equals(Object o) {
        if (!(o instanceof WordProbability)) {
            return false;
        }
        WordProbability rhs = (WordProbability) o;
        return new EqualsBuilder().append(getWord(), rhs.getWord()).append(getCategory(), rhs.getCategory()).isEquals();
    }

    public int compareTo(java.lang.Object o) {
        if (!(o instanceof WordProbability)) {
            throw new ClassCastException(o.getClass() + " is not a " + this.getClass());
        }
        WordProbability rhs = (WordProbability) o;
        return new CompareToBuilder().append(this.getCategory(), rhs.getCategory()).append(this.getWord(), rhs.getWord()).toComparison();
    }

    public String toString() {
        return new ToStringBuilder(this).append("word", word).append("category", category).append("probability", probability).append("matchingCount", matchingCount).append("nonMatchingCount", nonMatchingCount).toString();
    }

    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(word).append(category).toHashCode();
    }

}
4

1 回答 1

0

我在 JavaME 的 javadocs 中没有看到 Comparable。所以我认为它不存在。

你在哪里找到的?也许某些 Lib 或 JSR 已包含它。比您需要将其包含在项目设置中。

如果只需要接口,可以自己定义。

于 2013-10-29T12:24:58.487 回答