Java me 如何将记录添加到数组中

Java me 如何将记录添加到数组中,java-me,midp,Java Me,Midp,当我获取它并将其放入数组时,RecordStore出现问题,我得到了多个结果 我的意思是,当我有3条记录,通过enumerateRecords获取它,然后将其放入array[][]中,然后再次获取它,我知道再次获取是错误的方法,但是我如何才能将recordstore的resultset添加到array[][][]中,然后获取resultset的array[] 我的代码: public Table showRs(){ String sID = null,sName = null,sTOE

当我获取它并将其放入数组时,
RecordStore
出现问题,我得到了多个结果

我的意思是,当我有3条记录,通过
enumerateRecords
获取它,然后将其放入
array[][]
中,然后再次获取它,我知道再次获取是错误的方法,但是我如何才能将
recordstore
resultset
添加到
array[][][]
中,然后获取
resultset
array[]

我的代码:

 public Table showRs(){
    String sID = null,sName = null,sTOE = null;
    hrs.openRecordStore(hrs.getRecordnameBasic());
    //hrs.listofRecord();
    RecordEnumeration re;
    try {
        re = hrs.getRcs().enumerateRecords(null, null, true);
        while(re.hasNextElement()){
             byte[] recordBuffer = re.nextRecord();
             String record = new String(recordBuffer);

             //ID
             int iID = record.indexOf(";");
              sID = record.substring(0,iID);
             //Name
             int iName = record.indexOf(";", iID+1);
              sName = record.substring(iID + 1,iName);
             //Type of Est
             int iTOE = record.indexOf(";", iName + 1);
              sTOE = record.substring(iName + 1, iTOE);

              int rc = hrs.getRcs().getNumRecords();
                tb = new Table(mf, this, "List of record");
                TableCell cells[][] = new TableCell[rc][3];

                for(int i = 0; i< rc ; i++){
                System.out.println("-------" + sID);
                    cells[i][0] = new TableCell(CellType.STRING, sID, true);
                    cells[i][1] = new TableCell(CellType.STRING, sName, true);
                    cells[i][2] = new TableCell(CellType.STRING, sTOE, true);
                }
                String header[] = new String[]{"ID", "Name", "TypeOfEst"};
                tb.setData(new int[]{40,97,98}, header, cells);




        }


    } catch (Exception e) {
        e.printStackTrace();
    }

    return tb;
}
细胞类型

/* *要更改此模板,请选择工具|模板 *然后在编辑器中打开模板。 */

包ui.table

public class CellType {

        public static final int STRING = 0;
        public static final int NUMBER = 1;
        public static final int ITEM = 2;

}
单元编辑器

import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;


public class CellEditor extends  Form implements CommandListener {

     private MIDlet midlet = null;
    private Table previousScreen = null;
    private Command backCommand = null;
    private Command OKCommand = null;
    private TextField textField;
    private ChoiceGroup choiceGroup;
    private TableCell cell;

    public CellEditor(MIDlet midlet, Table previousScreen, String title) {
        super(title);
        this.midlet = midlet;
        this.previousScreen = previousScreen;
        initialize();
    }

    private void initialize() {
        backCommand = new Command("Back", Command.BACK, 1);
        OKCommand = new Command("OK", Command.OK, 1);
        addCommand(backCommand);
        addCommand(OKCommand);
        setCommandListener(this);
    }

    public void setCell(TableCell cell) {
        this.cell = cell;
        deleteAll();
        if (cell.cellType == CellType.STRING) {
            textField = getTextField();
            textField.setConstraints(TextField.ANY);
            textField.setString(cell.cellText);
            append(textField);
        } else if (cell.cellType == CellType.NUMBER) {
            textField = getTextField();
            textField.setConstraints(TextField.NUMERIC);
            textField.setString(cell.cellText);
            append(textField);
        } else {
            choiceGroup=getChoiceGroup();
            choiceGroup.deleteAll();
            for (int i = 0; i < cell.itemOptions.length; i++) {
                choiceGroup.append(cell.itemOptions[i], null);
                if (cell.cellText.equals(cell.itemOptions[i])) {
                    choiceGroup.setSelectedIndex(i, true);
                }
            }
            append(choiceGroup);
        }
    }

    public TextField getTextField() {
        if (textField == null) {
            textField = new TextField("", "", 300, TextField.ANY);
        }
        return textField;
    }

    public ChoiceGroup getChoiceGroup() {
        if (choiceGroup == null) {
            choiceGroup = new ChoiceGroup("", ChoiceGroup.EXCLUSIVE);
        }
        return choiceGroup;
    }

    public void commandAction(Command com, Displayable display) {

        if (com == backCommand) {
            Display.getDisplay(midlet).setCurrent(previousScreen);
        } else if (com == OKCommand) {
            if (cell.cellType == CellType.ITEM) {
                previousScreen.cells[previousScreen.focusRow][previousScreen.focusCol].cellText = choiceGroup.getString(choiceGroup.getSelectedIndex());
            } else {
                previousScreen.cells[previousScreen.focusRow][previousScreen.focusCol].cellText = textField.getString();
            }
            previousScreen.calculateTableHeight();
            Display.getDisplay(midlet).setCurrent(previousScreen);
        }
    }

}
import javax.microedition.lcdui.ChoiceGroup;
导入javax.microedition.lcdui.Command;
导入javax.microedition.lcdui.CommandListener;
导入javax.microedition.lcdui.Display;
导入javax.microedition.lcdui.displaybable;
导入javax.microedition.lcdui.Form;
导入javax.microedition.lcdui.TextField;
导入javax.microedition.midlet.midlet;
公共类CellEditor扩展表单实现CommandListener{
私有MIDlet MIDlet=null;
private Table previousScreen=null;
私有命令backCommand=null;
私有命令OKCommand=null;
私有文本字段文本字段;
私人选择小组选择小组;
私有表细胞;
公共CellEditor(MIDlet MIDlet、表前屏幕、字符串标题){
超级(标题);
this.midlet=midlet;
this.previousScreen=previousScreen;
初始化();
}
私有void初始化(){
backCommand=新命令(“Back”,Command.Back,1);
OKCommand=新命令(“OK”,Command.OK,1);
addCommand(backCommand);
addCommand(OKCommand);
setCommandListener(这个);
}
公共空集合单元格(表格单元格){
这个细胞=细胞;
deleteAll();
if(cell.cellType==cellType.STRING){
textField=getTextField();
textField.setConstraints(textField.ANY);
textField.setString(cell.cellText);
追加(textField);
}else if(cell.cellType==cellType.NUMBER){
textField=getTextField();
textField.setConstraints(textField.NUMERIC);
textField.setString(cell.cellText);
追加(textField);
}否则{
choiceGroup=getChoiceGroup();
choiceGroup.deleteAll();
for(int i=0;i

我想从
ResultSet
中输出数据,但问题究竟出在哪里还不太清楚,但感觉您最好尝试删除
循环的内部
,并将表/单元格声明移到
之外,而

 //...
    String sID = null, sName = null, sTOE = null;
    hrs.openRecordStore(hrs.getRecordnameBasic());
    //hrs.listofRecord();
    RecordEnumeration re;
    try {
        // move table / cells declaration outside of while:
        int rc = hrs.getRcs().getNumRecords();
        tb = new Table(mf, this, "List of record");
        TableCell cells[][] = new TableCell[rc][3];
        int i = 0;

        re = hrs.getRcs().enumerateRecords(null, null, true);
        while(re.hasNextElement()){
             byte[] recordBuffer = re.nextRecord();
             //... stuff that was there
             sTOE = record.substring(iName + 1, iTOE);

             // drop that loop - for(int i = 0; i< rc ; i++){
             System.out.println("-------" + sID);
             cells[i][0] = new TableCell(CellType.STRING, sID, true);
             cells[i][1] = new TableCell(CellType.STRING, sName, true);
             cells[i][2] = new TableCell(CellType.STRING, sTOE, true);
             i++;
        }
        String header[] = new String[]{"ID", "Name", "TypeOfEst"};
        tb.setData(new int[]{40,97,98}, header, cells);
    } catch (Exception e) {
        e.printStackTrace();
    }
//...
/。。。
字符串sID=null,sName=null,sTOE=null;
hrs.openRecordStore(hrs.getRecordnameBasic());
//hrs.listofRecord();
记录枚举;
试一试{
//将表格/单元格声明移到while之外:
int rc=hrs.getRcs().getNumRecords();
tb=新表(mf,这是“记录列表”);
TableCell单元格[][]=新的TableCell[rc][3];
int i=0;
re=hrs.getRcs().enumerateRecords(null、null、true);
while(re.hasNextElement()){
字节[]recordBuffer=re.nextRecord();
//…那里的东西
sTOE=记录子串(iName+1,iTOE);
//删除该循环-for(inti=0;i
问题到底出在哪里还不太清楚,但感觉您最好尝试删除
循环的内部
,并将表/单元格声明移到
之外,而

 //...
    String sID = null, sName = null, sTOE = null;
    hrs.openRecordStore(hrs.getRecordnameBasic());
    //hrs.listofRecord();
    RecordEnumeration re;
    try {
        // move table / cells declaration outside of while:
        int rc = hrs.getRcs().getNumRecords();
        tb = new Table(mf, this, "List of record");
        TableCell cells[][] = new TableCell[rc][3];
        int i = 0;

        re = hrs.getRcs().enumerateRecords(null, null, true);
        while(re.hasNextElement()){
             byte[] recordBuffer = re.nextRecord();
             //... stuff that was there
             sTOE = record.substring(iName + 1, iTOE);

             // drop that loop - for(int i = 0; i< rc ; i++){
             System.out.println("-------" + sID);
             cells[i][0] = new TableCell(CellType.STRING, sID, true);
             cells[i][1] = new TableCell(CellType.STRING, sName, true);
             cells[i][2] = new TableCell(CellType.STRING, sTOE, true);
             i++;
        }
        String header[] = new String[]{"ID", "Name", "TypeOfEst"};
        tb.setData(new int[]{40,97,98}, header, cells);
    } catch (Exception e) {
        e.printStackTrace();
    }
//...
/。。。
字符串sID=null,sName=null,sTOE=null;
hrs.openRecordStore(hrs.getRecordnameBasic());
//hrs.listofRecord();
记录枚举;
试一试{
//将表格/单元格声明移到while之外:
int rc=hrs.getRcs().getNumRecords();
tb=新表(mf,这是“记录列表”);
TableCell单元格[][]=新的TableCell[rc][3];
int i=0;
re=hrs.getRcs().enumerateRecords(null、null、true);
虽然
 //...
    String sID = null, sName = null, sTOE = null;
    hrs.openRecordStore(hrs.getRecordnameBasic());
    //hrs.listofRecord();
    RecordEnumeration re;
    try {
        // move table / cells declaration outside of while:
        int rc = hrs.getRcs().getNumRecords();
        tb = new Table(mf, this, "List of record");
        TableCell cells[][] = new TableCell[rc][3];
        int i = 0;

        re = hrs.getRcs().enumerateRecords(null, null, true);
        while(re.hasNextElement()){
             byte[] recordBuffer = re.nextRecord();
             //... stuff that was there
             sTOE = record.substring(iName + 1, iTOE);

             // drop that loop - for(int i = 0; i< rc ; i++){
             System.out.println("-------" + sID);
             cells[i][0] = new TableCell(CellType.STRING, sID, true);
             cells[i][1] = new TableCell(CellType.STRING, sName, true);
             cells[i][2] = new TableCell(CellType.STRING, sTOE, true);
             i++;
        }
        String header[] = new String[]{"ID", "Name", "TypeOfEst"};
        tb.setData(new int[]{40,97,98}, header, cells);
    } catch (Exception e) {
        e.printStackTrace();
    }
//...