android - javaNullPointer on display.getRotation() -
after having comment code know error was, found came mdisplay.getrotation(). general idea of code information accelerometer when it's in orientation. here's code
public void onsensorchanged(sensorevent event) { // todo auto-generated method stub // récupérer les valeurs du capteur float x, y, z; string s1 = "stringx", s2 = "stringy", s3 = "stringz"; if (event.sensor.gettype() == sensor.type_accelerometer) { switch (mdisplay.getrotation()) { case surface.rotation_0: x = event.values[0]; y = event.values[1]; s1 = "" + x; s2 = "" + y; break; case surface.rotation_90: x = -event.values[1]; y = event.values[0]; s1 = "" + x; s2 = "" + y; break; case surface.rotation_180: x = -event.values[0]; y = -event.values[1]; s1 = "" + x; s2 = "" + y; break; case surface.rotation_270: x = event.values[1]; y = -event.values[0]; s1 = "" + x; s2 = "" + y; break; } z = event.values[2]; s3 = "" + z; tvx.settext(s1); tvy.settext(s2); tvz.settext(s3); } }
i have declared display before oncreate() a
private display mdisplay;
but still have javanullpointer :s
thank guys.
you need
mdisplay = ((windowmanager) getsystemservice(context.window_service)).getdefaultdisplay();
Comments
Post a Comment