0

I am wondering how can I check if a sensor value is less than 1?

For example:

public void onSensorChanged(SensorEvent event) {
    if (event.values[1] < 1) { // How to check if sensor is lower then 1.00
        // Do something
    }
}

This currently crashing my app.

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
Mjafko
  • 151
  • 1
  • 2
  • 13
  • Show the logcat output. Check if your `event` variable is null and if size of values is greater than 1. – K Neeraj Lal Jan 17 '17 at 10:00
  • use if( event.values.length>1 && event.values[1] < 1 ) { // check if sensor is lower then 1.00 // Do something } – Saurabh Jan 17 '17 at 10:01
  • Sorry guys. I get error when I had Display.setText(x); this in IF. Just added Display.setText("" + x); and works. Sorry again! – Mjafko Jan 17 '17 at 10:04
  • 1
    Please read [ask] and improve your question accordingly. Most people are patient with beginner questions but as is, it may get some downvotes for (missing) quality. – Fildor Jan 17 '17 at 10:05
  • @Mjafko *"This currently gives me a crash"* — You should always add the stacktrace to the question. What's the error message? What does the [Logcat](http://stackoverflow.com/q/7188115/507738) say? – MC Emperor Jan 17 '17 at 12:46

0 Answers0