I have a function that receives a number (milliseconds to be precise) via Bluetooth.
byte[] encodedBytes = new byte[readBufferPosition];
System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "UTF-8");
readBufferPosition = 0;
started = "";
int myInt;
if (data != "") {
try{
myInt = new Integer(data);
long seconds = TimeUnit.MILLISECONDS.toSeconds(myInt);
}catch(NumberFormatException ex){
System.err.println("NumberFormatException "+ ex.getMessage());
}
...
} else {
...
}
The above try throws:
NumberFormatException Invalid int: "8250
I think the data received contains more then just the milliseconds, but how can I find that out, when I do
myLabel.setText(data);
it shows me: 8250
Any ideas?
new Integer(data.trim());can be a\nmyInt = Integer.valueOf(data);