I’ve run into a really weird situation. I’m doing the following in Java (through Eclipse Galileo) on the Android 2.1 platform:
// Get gravity & geomagnetic data to return to the caller.
final int SIZE_GRAVITY = 3, SIZE_GEOMAGNETIC = 3;
final float[] NOT_USED = null;
float[] outGravity = new float[SIZE_GRAVITY];
float[] outGeomagnetic = new float[SIZE_GEOMAGNETIC];
final String NO_DATA_COULD_BE_READ = null;
boolean succeeded = SensorManager.getRotationMatrix(NOT_USED, NOT_USED, outGravity, outGeomagnetic);
if (!succeeded)
{
return NO_DATA_COULD_BE_READ;
}
Log.v("Test", "This should be printed - but it isn't!!");
// Prepare the data to return.
final int X = 0, Y = 1, Z = 2;
final String FIELD_SEPARATOR = ",", VECTOR_SEPARATOR = ";";
String returnValue = "" +
outGravity[X] + FIELD_SEPARATOR +
outGravity[Y] + FIELD_SEPARATOR +
outGravity[Z] + VECTOR_SEPARATOR +
outGeomagnetic[X] + FIELD_SEPARATOR +
outGeomagnetic[Y] + FIELD_SEPARATOR +
outGeomagnetic[Z];
// Return data.
return returnValue;
When SensorManager.getRotationMatrix(...) returns false, the Eclipse debugger shows that the if-statement that says if (!succeeded) suddenly jumps to return returnValue;. No exception is thrown and LogCat – even on verbose mode – receives no unusual message. It doesn’t even receive the message I put in the code. I tried the obvious clean-and-restart-Eclipse approach and that didn’t help. I’m very confused.
The Eclipse debugger is telling me that the second return statement is being called. However, putting additional print statements in shows that the first return statement is actually the one being reached. Perhaps I’ve stumbled across an Eclipse bug? Or anyone could explain this anomaly?
How are you sure that it jumps to the last
return? You have areturnin the if, this is most likely this one which is called.