Hi i have a string of numbers and want to put them into a float array so i can access the values.
// this bit works fine, data is split into string array.
String fdata[] = data.split(",");
Float array_f[] = new Float(fdata.length);
// this is the bit which throws an error and causes my app to crash.
for (int i = 0; i < fdata.length; i++){
float y = Float.parseFloat(fdata[i]);
array_f[i] = y;
}
The error is a
java nullpointerexception: attempt to invoke virtual method java.lang.string java.lang.split(java.lang.string) on a null object reference.
thanks
adding to this i think i need to explain a bit more, so i provided more code to show what im trying to do.
String data; //does this need to define the number of bytes needed then?
start_Acq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
channel_a = String.valueOf(channel_Acq.getSelectedItem());
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
connection.start_acquisition(channel_a);
data = connection.start_acquisition(channel_a);
connection.stop_acquisition();
}catch (Exception e ){
e.printStackTrace();
}
}
});thread.start();
data_recived.setText(data);
String fdata[] = data.split(",");
Float array_f[] = new Float[fdata.length];
for(int i = 0; i<fdata.length; i++){
float y = Float.parseFloat(fdata[i]);
array_f[i] = y;
}
}
});