当我在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方法,正在上面调用&#34; ls1.compareTo(ls2);&#34;并使用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());
}
答案 0 :(得分:0)
Codename One实现了Java的一个子集,这意味着缺少一些东西。 Painfully Number缺失,并且某些接口未实现,因为它们在Java SE中。
请注意,这样做的好处是,Codename One iOS应用程序可以小到3mb,而不是50mb的最低起点......
对于字符串比较,您可以使用类似CaseInsensitiveOrder的内容进行常规整数比较,例如/**
* printableObject extends Printable
*/
public static boolean print(Object printableObject, String printer_name) throws InterruptedException {
InputStream printerTest = new ByteArrayInputStream("".getBytes());
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc myDoc = new SimpleDoc(printableObject, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
Doc docTest = new SimpleDoc(printerTest, flavor, null);
HashPrintServiceAttributeSet aset = new HashPrintServiceAttributeSet();
PrintRequestAttributeSet rset = new HashPrintRequestAttributeSet();
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
PrinterName printer = new PrinterName(printer_name, null);
rset.add(OrientationRequested.PORTRAIT);
rset.add(MediaSizeName.INVOICE);
aset.add(printer);
services = PrintServiceLookup.lookupPrintServices(null, aset);
if (!priterIsReady(services[0], 5)) {
return false;
}
if (services != null) {
try {
DocPrintJob docPrintJobTest = services[0].createPrintJob();
docPrintJobTest.print(docTest, rset);
if (!priterIsReady(services[0], 5)) {
return false;
}
DocPrintJob job = services[0].createPrintJob();
job.print(myDoc, rset);
Thread.sleep(300);
if (priterIsReady(services[0], 5)) {
DocPrintJob job2 = services[0].createPrintJob();
job2.print(docTest, rset);
return priterIsReady(services[0], 5);
} else {
return false;
}
} catch (ArrayIndexOutOfBoundsException ex) {
ex.printStackTrace();
} catch (PrintException pe) {
pe.printStackTrace();
}
}
return false;
}
public static boolean priterIsReady(PrintService printer, int max) throws InterruptedException {
int count = 0;
while (count < max) {
AttributeSet att = printer.getAttributes();
for (Attribute a : att.toArray()) {
String attributeName;
String attributeValue;
attributeName = a.getName();
attributeValue = att.get(a.getClass()).toString();
if (attributeName.equals("queued-job-count")) {
if (Integer.valueOf(attributeValue) == 0) {
return true;
} else {
System.err.println(">>> queued-job-count: " + Integer.valueOf(attributeValue));
}
}
}
Thread.sleep(600 + 600 / 5 * count);
count = count + 1;
}
return false;
}
之类的内容可以很好地工作并满足接口契约。