Unable to connect after unexpected application closure

edited November 2016 in Android
Hi there,

to shortly summarize the setup for a bug I encountered:
  • I started streaming accelerometer, gyroscope and magnetometer readings from a MetaMotion R in an Android App
  • My app force closed on account of an unrelated error, so that I was not able to disable and stop the different modules and to disconnect from the board
  • Upon trying to restart my app, I get the following exception, when I call mboard.connect()
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: de.kinemic.metawearhandler, PID: 24150
            java.lang.NullPointerException: Attempt to invoke interface method 
'void com.mbientlab.metawear.RouteManager$MessageHandler.process(com.mbientlab.metawear.Message)' on a null object reference
                at com.mbientlab.metawear.impl.DefaultMetaWearBoard$45$1.run(DefaultMetaWearBoard.java:3964)
                at android.os.Handler.handleCallback(Handler.java:751)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:154)
                at android.app.ActivityThread.main(ActivityThread.java:6077)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Comments

  • I tried to have a look into DefaultMetaWearBoard.java and the exception occurs inside the receivedModuleInfo(ModuleInfo info) method, specifically inside the branch if (info.id() == InfoRegister.ACCELEROMETER.moduleOpcode()) and case Constant.BMI160_IMPLEMENTATION: 
    responses.put(new ResponseHeader(Bmi160AccelerometerRegister.PACKED_ACC_DATA), new ResponseProcessor() {
    @Override
    public Response process(byte[] response) {
    final Queue<byte[]> unpacked= unpackData(response);
    final RouteManager.MessageHandler handler= responseProcessors.get(new ResponseHeader(response[0], response[1]));
    conn.executeTask(new Runnable() {
    @Override
    public void run() {
    while(!unpacked.isEmpty()) {
    handler.process(new Bmi160ThreeAxisMessage(unpacked.poll(), bmi160AccRange.scale()));
    }
    }
    });
    return null;
    }
    });

    My guess is that it has something to do with the accelerometer/gyro/magnetometer modules still being active on the board, but I have no idea what exactly.

    I could resolve this bug by connecting and using the board using the pymetawear library on Linux, but I was not able to do anything under Android, as I was not even able to reconnect.
  • The stack trace says the crash occurred on line 3964 which combined with the NPE suggests I need to add a "if (handler != null)" check.
  • This has been fixed in the v2.7.2 API.
  • Hi,

    I just received a similar error again (now related to the gyro, not the acc), this time in line 4211
    I am using API 2.7.2

    E/AndroidRuntime: FATAL EXCEPTION: main
                                                       Process: de.kinemic.metawearhandler, PID: 16315
                                                       java.lang.NullPointerException: Attempt to invoke interface method 'void com.mbientlab.metawear.RouteManager$MessageHandler.process(com.mbientlab.metawear.Message)' on a null object reference
                                                           at com.mbientlab.metawear.impl.DefaultMetaWearBoard$62$1.run(DefaultMetaWearBoard.java:4211)
                                                           at android.os.Handler.handleCallback(Handler.java:751)
                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                           at android.os.Looper.loop(Looper.java:154)
                                                           at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
  • Hrm..ok.  I'll address this in the next API update
  • @mgeorgi ;
    Try api v2.8.0
This discussion has been closed.