I have a small array of doubles that I fill with data. Then, since a Datagram can only transmit a single Java data type and I want to transmit everything in one packet, I build a String with this data by iterating through the array of 7 double elements, delimiting each by a single space, using the concatenation operator '+'. Then I transmit the String, and the receiver will use StreamTokenizer to get each space-delimited value and store it in its own double array.
So at the point of decoding the String into separate double values:
So the statement I marked with the comment above is obviously the problem; the elements of temp are a double, but the StringTokenizer's nextToken() function return a String. Trying to cast to double didn't work. So it seems like what I would need is an equivalent to the atof() function from C.
Note that I am developing on a Sun SPOT, which uses a Squawk VM and based on the Java Microedition, CLDC compatible. I'm not sure what that all means, but it is possible I don't have all the methods that J2SE has. But I have not found anything I needed but wasn't available yet, so it probably has what I need. Thanks for any help.
So at the point of decoding the String into separate double values:
private void getDataFromString(String data)
{
double [] temp = new double[7];
int n = 0;
StringTokenizer st = new StringTokenizer(data);
while (st.hasMoreTokens())
{
temp[n] = st.nextToken(); // OOPS - can't do this of course
n++;
}
}
So the statement I marked with the comment above is obviously the problem; the elements of temp are a double, but the StringTokenizer's nextToken() function return a String. Trying to cast to double didn't work. So it seems like what I would need is an equivalent to the atof() function from C.
Note that I am developing on a Sun SPOT, which uses a Squawk VM and based on the Java Microedition, CLDC compatible. I'm not sure what that all means, but it is possible I don't have all the methods that J2SE has. But I have not found anything I needed but wasn't available yet, so it probably has what I need. Thanks for any help.