Hello,

I am facing getting probelm in writing tag to Mifair RFID cad. I got Class Cast Exception. The following is my code. Please take a look at it and let me know what is wrong in it.

NDEFTagConnection conn = null;
try {
// Open connection to NDEF tag
conn = (NDEFTagConnection) Connector.open(url);
// Read image from phone to ByteArrayOutputStream
InputStream is = getClass().getResourceAsStream(data);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c;
while ((c = is.read()) != -1) {
baos.write(c);
}
// Create NDEF Record to be added to NDEF Message
NDEFRecord recordToWrite = new NDEFRecord(new NDEFRecordType(
NDEFRecordType.UNKNOWN, "text"), null, baos
.toByteArray());
// Create NDEF Message and add created record in it.
NDEFMessage write_container = new NDEFMessage();
write_container.appendRecord(recordToWrite);
// Write NDEF Message to tag
conn.writeNDEF(write_container);
mainForm.append("record written successfully");
// form.append("Image witten");
} catch (IOException e)
{
mainForm.append("in write 1"+e.toString());
} catch (Exception e)
{
mainForm.append("in write 2"+e.toString());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (IOException e) {
mainForm.append("in write"+e.toString());
}


Please take a look and let me know what is wrong in it.