1
votes

It appears that code that runs locally will not build when I send an Android build on CN1 3.5.2. Can anyone tell me if I'm doing something wrong in my code versus it being an environment issue?

The error message I get when trying to build for Android is "... error: cannot find symbol method compare(int,int)" and another one for the sort method on Vector class.

The implicated line is using the Integer.compare(int,int) method.

Here's the code that uses the Sort method:

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;
    }

And here's the compareTo method I wrote that is being called above "ls1.compareTo(ls2);" and uses the Integer.compare(int, int) method that produces the other compiler error:

@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());
    }
1

1 Answers

0
votes

Codename One implements a subset of Java which means some things are missing. Painfully Number is missing and some interfaces aren't implemented as they are in Java SE.

Notice that the upside of this is that a Codename One iOS application can be as small as 3mb as opposed to a 50mb minimum starting point...

For string comparison you can use something like CaseInsensitiveOrder for regular integer comparisons things like intA - intB will work rather well and satisfy the interface contract.