Runtime fatal error on using gpio.pin((byte) 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(DeviceSetupActivityFragment.java:192) at com.mbientlab.metawear.tutorial.starter.-$$Lambda$DeviceSetupActivityFragment$SLM0uxH3iZwDut3wex8hCYKi8no.onCheckedChanged(lambda)
at android.widget.CompoundButton.setChecked(CompoundButton.java:156)
at android.widget.Switch.setChecked(Switch.java:1070)
at android.widget.Switch.toggle(Switch.java:1065)
at android.widget.CompoundButton.performClick(CompoundButton.java:120)
at android.view.View$PerformClick.run(View.java:21196)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

My code in DeviceSetupActivityFragment

   ** // GPIO (Valid for MetaMotion R Only)
    SW_gas_sensor=view.findViewById(R.id.gpio_ctrl);
    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
            gpio_gas_sensor.pin((byte) 7).setOutput();
        } else {
            // output 0V on pin 7 of MetaMotion R Board
            //gpio_gas_sensor.pin((byte) 7).clearOutput();
            metawear.tearDown();
        }**
    });

Comments

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

Sign In or Register to comment.