I'm quite new to android so forgive me if I am asking a dead simple question.
Basically What I want to do is Display a number. when the value of Y, event.value[1] is between 1 and 7.
I can display values of X Y Z position. but as soon as I add if statement to check my app stops working (See code below)
I really need someones help please.
Thanks you for your help.
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
int YValueMin = 1;
int YValueMax = 7;
accelero.setText("X: "+event.values[0]+
"\nY: "+event.values[1]+
"\nZ: "+event.values[2]);
if (y >= YValueMin && y <= YValueMax ){
RepCounter.setText("1");
}
else {
RepCounter.setText(" ");
}
}
What does the logcat say when it crashes?
It is highly likely that your RepCounter is null, you can check this using the debugger.
Edit: Please change your code to the following, it could be a solution. If not, I will need the full source code to make sure RepCounter isn't a class or uninitialised object.
public void onSensorChanged(SensorEvent event)
{
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
int YValueMin = 1;
int YValueMax = 7;
accelero.setText("X: " + event.values[0] + "\nY: " + event.values[1] + "\nZ: " + event.values[2]);
if(y >= YValueMin && y <= YValueMax)
{
RepCounter.setText("1");
}
else
{
RepCounter.setText(" ");
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With