【问题标题】:CodenameOne error on Build: "error: cannot find symbol method compare(int, int)"Build 上的 CodenameOne 错误:“错误:找不到符号方法比较(int,int)”
【发布时间】:2016-09-10 13:00:55
【问题描述】:

当我在 CN1 3.5.2 上发送 Android 构建时,本地运行的代码似乎不会构建。谁能告诉我我的代码是否有问题而不是环境问题?

我在尝试为 Android 构建时收到的错误消息是“...错误:找不到符号方法 compare(int,int)”,另一个是 Vector 类的排序方法。

涉及的行是使用 Integer.compare(int,int) 方法。

下面是使用 Sort 方法的代码:

protected Vector getLearnableListModel(Vector<String> modulesSelected,  Vector<String> categoriesSelected){
        Vector result = MyApplication.moduleSet.getLearnableListModel(modulesSelected, categoriesSelected);
        result.sort(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                LearnableSpec ls1 = (LearnableSpec) o1;
                LearnableSpec ls2 = (LearnableSpec) o2;
                return ls1.compareTo(ls2);
            }
        });
        return result;
    }

这是我编写的 compareTo 方法,在“ls1.compareTo(ls2);”上方调用并使用产生其他编译器错误的 Integer.compare(int, int) 方法:

@Override
    public int compareTo(LearnableSpec other) {
        LinkedHashMap modLHM = MyApplication.moduleSet.getAllModules();
        LinkedHashMap catLHM = MyApplication.moduleSet.getAllCategories();

        int i = Integer.compare(indexOfLinkedHashMapKey(modLHM, moduleID), indexOfLinkedHashMapKey(modLHM, other.getModuleID()));
        if (i != 0) return i;

        i = Integer.compare(indexOfLinkedHashMapKey(catLHM,categoryID),indexOfLinkedHashMapKey(catLHM,other.getCategoryID()));
        if (i != 0) return i;

        return name.compareTo(other.getName());
    }

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    Codename One 实现了 Java 的一个子集,这意味着缺少一些东西。痛苦的是 Number 丢失了,并且一些接口没有像在 Java SE 中那样实现。

    请注意,这样做的好处是 Codename One iOS 应用程序可以小至 3mb,而不是 50mb 的最小起点...

    对于字符串比较,您可以使用CaseInsensitiveOrder 之类的东西进行常规整数比较,intA - intB 之类的东西会很好地工作并满足接口协定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 2018-01-23
      • 2016-11-10
      • 1970-01-01
      • 2015-02-06
      • 2014-01-25
      • 2013-10-28
      相关资源
      最近更新 更多