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() {
        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",
                        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() {
            public void configure(RouteComponent source) {
        }).continueWith(new Continuation<Route, Void>() {
            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);


                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(
        at com.mbientlab.metawear.impl.StreamedDataConsumer$2.onResponseReceived(
        at com.mbientlab.metawear.impl.JseMetaWearBoard$5.onMwNotifyCharChanged(
        at android.bluetooth.BluetoothGatt$1$
        at android.bluetooth.BluetoothGatt.runOrQueueCallback(
        at android.bluetooth.BluetoothGatt.access$200(
        at android.bluetooth.BluetoothGatt$1.onNotify(
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(
        at android.os.Binder.execTransact(

( Is the fos


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

Sign In or Register to comment.