serialization problem with folder

Hi, well when I try to use the serialization code, I have a problem changing or choosing the location that the file will have
I change The de fos:
fos = openFileOutput("acceleration_data", MODE_PRIVATE); to fos = openFileOutput(Environment.getExternalStorageDirectory() + "/Download/"+1+".csv", MODE_PRIVATE);

oiginal Code

public class MainActivity extends Activity implements ServiceConnection {
    // Declared as static variable so no reference to outer Activity class
    // is held by this object
    private static Subscriber DATA_HANDLER = new Subscriber() {
        @Override
        public void apply(Data data, Object... env) {
            try {
                FileOutputStream fos = (FileOutputStream) env[0];
                Acceleration casted = data.value(Acceleration.class);
                fos.write(String.format(Locale.US, "%s,%.3f,%.3f,%.3f%n",
                        data.formattedTimestamp(),
                        casted.x(), casted.y(), casted.z()).getBytes());
            } catch (IOException ex) {
                Log.e("MainActivity", "Error writing to file", ex);
            }
        }
    };

    private FileOutputStream fos;

    public void setup() {
        acceleration.addRouteAsync(new RouteBuilder() {
            @Override
            public void configure(RouteComponent source) {
                source.stream(DATA_HANDLER);
            }
        }).continueWith(new Continuation<Route, Void>() {
            @Override
            public Void then(Task<Route> task) throws Exception {
                fos = openFileOutput("acceleration_data", MODE_PRIVATE);
                // Pass the output stream to the first Subscriber (idx 0)
                // by seting its environment
                task.getResult().setEnvironment(0, fos);

                accelerometer.acceleration().start();
                accelerometer.start();

                return null;
            }
        });
    }
}

Error Code:

W/BluetoothGatt: Unhandled exception in callback
    java.lang.NullPointerException: Attempt to read from null array
        at com.example.mmripre.MainActivity$1.apply(MainActivity.java:63)
        at com.mbientlab.metawear.impl.DeviceDataConsumer.call(DeviceDataConsumer.java:51)
        at com.mbientlab.metawear.impl.StreamedDataConsumer$2.onResponseReceived(StreamedDataConsumer.java:124)
        at com.mbientlab.metawear.impl.JseMetaWearBoard$5.onMwNotifyCharChanged(JseMetaWearBoard.java:576)
        at com.mbientlab.metawear.android.BtleService$1.onCharacteristicChanged(BtleService.java:228)
        at android.bluetooth.BluetoothGatt$1$8.run(BluetoothGatt.java:519)
        at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:876)
        at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:43)
        at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:513)
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:185)
        at android.os.Binder.execTransact(Binder.java:739)

(MainActivity.java:63) Is the fos

Comments

  • Not sure this falls within metawear territory. Might have to refer to stackoverflow for this one.

Sign In or Register to comment.