android - RotationVector Sensor ArrayIndexOutOfBounds exception -
i coding app information sensors. have problem on rotation vector one. saw on official android website have 4 values sensor :
type_rotation_vector :
sensorevent.values[0] rotation vector component along x axis (x * sin(θ/2)).
sensorevent.values[1] rotation vector component along y axis (y * sin(θ/2)).
sensorevent.values[2] rotation vector component along z axis (z * sin(θ/2)).
sensorevent.values[3] scalar component of rotation vector ((cos(θ/2)).1
here's code :
@override public void onsensorchanged(sensorevent event) { // todo auto-generated method stub //get sensors values float x, y, z, s; string s1 = "stringx", s2 = "stringy", s3 = "stringz", s4 = "strings"; if (event.sensor.gettype() == sensor.type_rotation_vector) { x = event.values[0]; y = event.values[1]; z = event.values[2]; s = event.values[3]; // <============== error indicate line s1 = "" + x; s2 = "" + y; s3 = "" + z; s4 = "" + s; tvx.settext(s1); tvy.settext(s2); tvz.settext(s3); tvs.settext(s4); } }
here's log cat :
fatal exception: main java.lang.arrayindexoutofboundsexception: length=3; index=3 @ com.example.sensortnewtest.rotationvectorinfos.onsensorchanged(rotationvectorinfos.java:128) @ android.hardware.systemsensormanager$listenerdelegate$1.handlemessage(systemsensormanager.java:204) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5041) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) @ dalvik.system.nativestart.main(native method)
does mean event.values[3] not possible?
thank guys.
according the android documentation on sensorevent, fourth value (i.e. event.values[3]) optional, , present when values.length = 4. (search type_rotation_vector on web-page). you're encountering case it's not provided.
Comments
Post a Comment