为什么不能这样获取RMS里的记录?
String[] result={};
aBus=new Bus();
if(OK)
try{
byte[] data;
int number=rs.getNumRecords();
RecordFilter rf=new stationFilter();
RecordEnumeration re=rs.enumerateRecords(rf, null, false);
int i=0;
while(re.hasNextElement()){
int recordID=re.nextRecordId();
data=rs.getRecord(recordID);
aBus.changeFromByteArray(data);
result[i]=aBus.getline();
i++;
}
}
catch(Exception e){
aTextBox.setString( "获取记录的操作失败! ");
try{
rs.closeRecordStore();
System.out.println( "1.Closed ");
RecordStore.deleteRecordStore( "aRS ");
System.out.println( "delete OK ");
}
catch(Exception x){
}
}
如果把result改为String类型的就可以获取记录,为什么result为String[]类型就不行?
String result= " ";
aBus=new Bus();
if(OK)
try{
byte[] data;
int number=rs.getNumRecords();
RecordFilter rf=new lineFilter(); //add
RecordEnumeration re=rs.enumerateRecords(rf, null, false);
while(re.hasNextElement()){
int recordID=re.nextRecordId();
data=rs.getRecord(recordID);
aBus.changeFromByteArray(data);
result+=aBus.getline()+ "\n ";
}
aTextBox.setString(result);
}
catch(Exception e){
aTextBox.setString( "获取记录的操作失败! ");
try{
rs.closeRecordStore();
System.out.println( "1.Closed ");
RecordStore.deleteRecordStore( "aRS ");
System.out.println( "delete OK ");
}
catch(Exception x){
}
}
------解决方案--------------------String[] result={};
这里声明的数组长度为0
你往里面添加内容,就会出现数组下标越界的异常
在不确定个数的情况下
建议用Vector来存储,或者事先声明足够大的数组