How come I can't writeUTF to RMS?

时间:2015-07-08 15:40:15

标签: java java-me rms

I am developing an app using J2ME. The project is to store integer and string data into RMS.

The error shows that out.writeUTF(i.getNumberPlate()); is not working.

So any solution to solve this problem? The compiler cant even compile the project.

public class CarparkReservationParser {
    public static byte[] parseObj(CarparkReservation i) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream out;

        try {

            out = new DataOutputStream(baos);

            // write into string
            out.writeInt(i.getCarpark());
            out.writeUTF(i.getNumberPlate());
            out.writeUTF(i.getStudentID());
            out.writeUTF(i.getName());
            out.writeInt(i.getYear());
            out.writeInt(i.getMonth());

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

        // convert to byte array
        return baos.toByteArray();

    }
}

1 个答案:

答案 0 :(得分:0)

@ jack的评论是对的。 writeUTF接收String作为参数。如果getNumberPlate()未返回String,您必须更改代码。例如:

out.writeUTF(i.getNumberPlate().toString());