j2me中让人难受的问题
为何用以下代码对选出的记录集合排序不行:
try {
rs=RecordStore.openRecordStore( "phone ", false);
Filter fl=new Filter(tmpe,0);
Comparator cp=new Comparator();
RecordEnumeration re=rs.enumerateRecords(fl, cp, true);
mf.append( "查询结果为:\n ");
output(re,mf);
fl=new Filter(tmpe,1);
re=rs.enumerateRecords(fl, cp, true);
mf.append( "\n < <-------相关查询结果为:-------> > \n ");
output(re,mf);
rs.closeRecordStore();
}catch(Exception e){}
}break;
比较器:
import javax.microedition.rms.*;
public class Comparator implements RecordComparator {
public int compare(byte[] rec1, byte[] rec2) {
//获取记录的字符串
String r1 = new String(rec1);
String r2 = new String(rec2);
//使用String的compareTo()方法进行比较
if (r1.compareTo(r2) > 0)
return (RecordComparator.FOLLOWS);//大于
else if (r1.compareTo(r2) < 0)
return (RecordComparator.PRECEDES);//小于
else
return (RecordComparator.EQUIVALENT);//等于
}
}
望大虾们赐教
------解决方案--------------------用 system.out.pintln 打出来看看
------解决方案--------------------你要看看你的Record数据是怎么输入的?