Runtime fatal error on using 7).setOutput() on MetaMotion R Board

I got a fatal runtime NullPointerException when I try to instruct the gpio module to supply 3V out from pin 7.

Error message as shown below. My code is pasted after the error message.

05-29 11:13:59.758 2713-2713/com.mbientlab.metawear.tutorial.starter E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mbientlab.metawear.tutorial.starter, PID: 2713 java.lang.NullPointerException: Attempt to invoke interface method 'void com.mbientlab.metawear.module.Gpio$Pin.setOutput()' on a null object reference at com.mbientlab.metawear.tutorial.starter.DeviceSetupActivityFragment.lambda$onViewCreated$2$DeviceSetupActivityFragment( at com.mbientlab.metawear.tutorial.starter.-$$Lambda$DeviceSetupActivityFragment$SLM0uxH3iZwDut3wex8hCYKi8no.onCheckedChanged(lambda)
at android.widget.CompoundButton.setChecked(
at android.widget.Switch.setChecked(
at android.widget.Switch.toggle(
at android.widget.CompoundButton.performClick(
at android.view.View$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)

My code in DeviceSetupActivityFragment

   ** // GPIO (Valid for MetaMotion R Only)
    SW_gas_sensor.setOnCheckedChangeListener((buttonView, isChecked) -> {
        gpio_gas_sensor= metawear.getModule(Gpio.class);
        Log.i("Switch State=", "" + isChecked);
        if (isChecked) {
            // output 3V on pin 7 of MetaMotion R Board
        } else {
            // output 0V on pin 7 of MetaMotion R Board
            // 7).clearOutput();


  • Nevermind I think the reason is there is no such thing as GPIO pin 7

Sign In or Register to comment.