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();
}
}
答案 0 :(得分:0)
@ jack的评论是对的。 writeUTF
接收String作为参数。如果getNumberPlate()
未返回String
,您必须更改代码。例如:
out.writeUTF(i.getNumberPlate().toString());