Hallo Astar,
So I guess the exception is raised by this line of code:
Code:
NDEFMessage message = conn.readNDEF();
Is there any specific reason why you try to skip opening the connection on the second targetDetected event?
Code:
if(conn == null){
// if the target is detected for the second time, this part will be skipped.
conn = (NDEFTagConnection)Connector.open(url);
}
What happens now is that during your second targetDetected event, you try to access the previous connection to the NDEF tag. As that connection has been (forcefully) terminated by removing the tag from the reader, the conn object is no longer valid.
Each targetDetected event is triggered by bringing the tag in range of the phone. To achieve this, you have to move the tag out of range and then bring it in range again. This causes the connection to the tag to be completely reinitialized (i.e. the tag is powered down and the powered on again and a new connection to the tag is established).
Consequently with every targetDetected event you have to open a new connection to the tag (and when you are finished with reading/writing the tag you have to close the connection again.
br,
Michael