We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Dear Community.
Im new to java, and i have a crash in my application while starting it on my Android phone. P.s why i cant use the Code highlight in the Forum ?!?
FATAL EXCEPTION: Animation Thread
Process: processing.test.geolocation, PID: 17096
java.lang.IllegalStateException: Underflow in restore
at android.graphics.Canvas.restore(Native Method)
at processing.core.PGraphicsAndroid2D.popMatrix(Unknown Source)
at processing.core.PApplet.popMatrix(Unknown Source)
at processing.test.geolocation.Geolocation.drawmap(Geolocation.java:80)
at processing.test.geolocation.Geolocation.draw(Geolocation.java:63)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:841)
Here is my Code
/**
* <p>Ketai Sensor Library for Android: http://KetaiProject.org</p>
*
* <p>Ketai Location Features:
* <ul>
* <li>Uses GPS location data (latitude, longitude, altitude (if available)</li>
* <li>Updates if location changes by 1 meter, or every 10 seconds</li>
* <li>If unavailable, defaults to system provider (cell tower or WiFi network location)</li>
* </ul>
* <p>Syntax:
* <ul>
* <li>onLocationEvent(latitude, longitude, altitude)</li>
* <li>onLocationEvent(latitude, longitude)</li>
* <li>onLocationEvent(latitude, longitude, altitude)</li>
* </p>
* <p>Updated: 2012-10-21 Daniel Sauter/j.duran</p>
*/
//import ketai.sensors modules
import ketai.sensors.*;
double longitude, latitude, altitude;
KetaiLocation location;
void setup() {
//Screen Orientation LANDSCAPE, PORTRAIT is also possible
orientation(LANDSCAPE);
//Display text in the Upperscreen alligned Right
textAlign(UP, RIGHT);
//text Size
textSize(36);
//location is KetaiLocation
location = new KetaiLocation(this);
//set screen size, how is a dynamic size possible ?
//how could i make it possible to rotate screen
//orientation and change size during application is started
size(displayWidth, displayHeight);
}
void draw() {
//draw background in Green
background(78, 93, 75);
//Alert if no location provider is avaible
if (location.getProvider() == "none")
text("Location data is unavailable. \n" +
"Please check your location settings.", 0, 0, width, height);
//Display Latitude Longitude Altitude and Provider
else
text("Latitude: " + latitude + "\n" +
"Longitude: " + longitude + "\n" +
"Altitude: " + altitude + "\n" +
"Provider: " + location.getProvider(), 0, 0, width, height);
// getProvider() returns "gps" if GPS is available
// otherwise "network" (cell network) or "passive" (WiFi MACID)
// Execute function drawmap
drawmap();
}
void onLocationEvent(double _latitude, double _longitude, double _altitude)
{
longitude = _longitude;
latitude = _latitude;
altitude = _altitude;
println("lat/lon/alt: " + latitude + "/" + longitude + "/" + altitude);
}
void drawmap()
{
//convert latitude <- double to flatitude <- float
float flatitude = (float) latitude;
//convert longitude <- double to longitude <- float
float flongitude = (float) longitude;
//move matrix, current position SHOULD be in the MIDDLE of the screen.
translate((flatitude + (displayWidth / 2)), (flongitude + (displayHeight / 2)));
//pop Matrix
popMatrix();
//draw eclipse
ellipse (flatitude, flongitude, 10, 10);
}
Answers
Moved to Android category.
I doubt it will do anything, but you should try and move size() to the first line of setup(), as recommended everywhere...
you have a popMatrix() with no pushMatrix(). they need to match, and push should be first.
@gamecompile:: koogs is right as for the underflow error: no pushMatrix() before your translate(); but furthermore your popMatrix() is not at the good place if you want (as it s written in the comments) that the ellipse appears in the middle of the screen...It must be placed after the ellipse()....
Thank you very much. SOLVED
you can also accept an answer
Or several... I did it myself, hoping the OP will do it in the future (it is already nice to have marked the topic as solved).
thanks!