Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用ByteArrayoutPutStream保存和检索_Java_Rms - Fatal编程技术网

Java 无法使用ByteArrayoutPutStream保存和检索

Java 无法使用ByteArrayoutPutStream保存和检索,java,rms,Java,Rms,我正在制作这个J2ME应用程序,但当我试图保存时遇到了一些问题,我认为它保存得正确,但我不确定……但是当我检索它时,它给出了null 这就是我存储它们的方式 PAR par = new PAR(oldMonPay, newMonPay, oldInterest); par.setOldMPay(oldMonPay); par.setNewMPay(newMonPay); par.setOldInt(oldInterest); 这就

我正在制作这个J2ME应用程序,但当我试图保存时遇到了一些问题,我认为它保存得正确,但我不确定……但是当我检索它时,它给出了null

这就是我存储它们的方式

        PAR par = new PAR(oldMonPay, newMonPay, oldInterest);
        par.setOldMPay(oldMonPay);
        par.setNewMPay(newMonPay);
        par.setOldInt(oldInterest);
这就是我如何保存和检索

public static byte[] parseObjPAR(PAR p) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out;

    try {
        out = new DataOutputStream(baos);
        out.writeUTF(p.getNewMPay());
        out.writeUTF(p.getOldInt());
        out.writeUTF(p.getOldMPay());



    } catch (IOException e) {
    }
    return baos.toByteArray();
}

public static PAR parseByteArrPAR(byte[] b) {
    PAR p = null;
    ByteArrayInputStream bais;
    DataInputStream in;

    if (b != null) {
        try {
            bais = new ByteArrayInputStream(b);
            in = new DataInputStream(bais);
            p = new PAR(
                    in.readUTF(),
                    in.readUTF(),
                    in.readUTF());    
        } catch (IOException e) {
        }
    }
    return p;
}
这就是我显示检索到的信息的方式,还有一个问题,这不是显示所有的数据,而是只显示3条记录。我想前三个

 public void populatePAResult(PAR[] p) {
    try {
        for (int i = 0; i < p.length; i++) {
            String oldMP = p[i].getOldMPay();
            String newMP = p[i].getNewMPay();
            String oldI = p[i].getOldInt();



            result1.append("Day : " + oldMP, null);
            result1.append("Time : " + oldI, null);
            result1.append("Technology : " + newMP, null);

        }
    } catch (Exception e) {
    }
}
在写入数据的parseObjPAR方法中,顺序为:

out.writeUTF(p.getNewMPay());
out.writeUTF(p.getOldInt());
out.writeUTF(p.getOldMPay());
然而,当您读回并传递构造函数期望的顺序时,情况有所不同:

PAR par = new PAR(oldMonPay, newMonPay, oldInterest);

因此,即使它不是null,加载的数据也将无效。

您看到的问题是什么?知道会有帮助的!建议您在读/写方法中正确地实现异常处理-您正在默默地忽略我怀疑会有帮助的任何I/O错误,至少会将堆栈跟踪转储到控制台。它不会存储我认为的值,当我调用该字符串值时,它给出null。您指的是哪个字符串值?你有例外吗?或者,它不是按预期工作的吗?同样,在PARSEBOBPAR方法中编写PAR数据的顺序与PARSEBYTARRPAR中使用的构造函数的顺序不同。OK,我确定了这一点,所以现在我必须清除以前的数据吗?因为它又给空了你能再检查一下我的问题吗我已经编辑过了