Skip to content

Instantly share code, notes, and snippets.

@CodeWithSouma
Last active December 27, 2020 15:22
Show Gist options
  • Save CodeWithSouma/c61f439cd0a3c8da53068b47105f7983 to your computer and use it in GitHub Desktop.
Save CodeWithSouma/c61f439cd0a3c8da53068b47105f7983 to your computer and use it in GitHub Desktop.
Please help me to solve this problem
## Thsi code is taken from SensorMPU925X.java (PS-Lab android client)
scienceLab = ScienceLabCommon.scienceLab;
I2C i2c = scienceLab.i2c;// here i am trying to get i2c but it returns null
try {
if (i2c == null) throw new IOException("i2c not found"); // i add this line to check i2c is null or not
sensorMPU925X = new MPU925x(i2c);
} catch (IOException e) {
Log.d("ic2", "onCreate: "+e);
e.printStackTrace();
}
I need to pass i2c in the constructor MPU925x but i2c is null. For this,
I got a null pointer exception when touching the MPU925X sensor
from sensor list please help me how to fix this problem.
stack trace
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.pslab.communication.peripherals.I2C.writeBulk(int, int[])' on a null object reference
at io.pslab.communication.sensors.MPU925x.setGyroRange(MPU925x.java:80)
at io.pslab.communication.sensors.MPU925x.<init>(MPU925x.java:43)
at io.pslab.sensors.SensorMPU925X.onCreate(SensorMPU925X.java:103)
at android.app.Activity.performCreate(Activity.java:6303)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment