0

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();

    }
}
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Bryan Lum
  • 19
  • 1
  • 1
  • 4
  • It would probably help if you told us what errors the compiler gives. – mr_lou Jul 08 '15 at 16:12
  • 1
    Take a look at the return type of `getNumberPlate()`β€”it may not return a `String`, which is the type that `writeUTF` requires. – Jack Jul 08 '15 at 20:12

1 Answers1

0

@jack's comment is right. writeUTF receives a String as parameter. If getNumberPlate() does not return a String you must change your code. For example:

out.writeUTF(i.getNumberPlate().toString());
Telmo Pimentel Mota
  • 4,033
  • 16
  • 22