Why do I get an ArrayIndexOutOfBoundsException? (Solved)
in
Contributed Library Questions
•
7 months ago
I've got the code from:
https://launchpad.net/gpxrenderer
Tried to run it with my own .gpx and then I get:
ArrayIndexOutOfBoundsException: 0 >= 0
Invalid input: `?' (0xfeff), SystemID='file:.', Line=1
at processing.xml.XMLUtil.errorInvalidInput(Unknown Source)
at processing.xml.StdXMLParser.scanData(Unknown Source)
at processing.xml.StdXMLParser.parse(Unknown Source)
at processing.xml.XMLElement.init(Unknown Source)
at processing.xml.XMLElement.<init>(Unknown Source)
at tomc.gpx.GPX.parse(GPX.java:62)
at DrawingGPX.setup(DrawingGPX.java:103)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:427)
at tomc.gpx.GPX.getTrack(GPX.java:90)
at DrawingGPX.draw(DrawingGPX.java:130)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
I've did read the topics about this problem, but i'm too noob to know how to solve it.
Maybe my .gpx file has to many tracks for the array?
Love to get some input from someone to whom it does make sense.
Here is the code:
- /*
- Copyright (c) 2009 Steven M. Ottens
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
- import tomc.gpx.*;
- //<EDIT> Movie
- //Note: the library and settings used to create movies only work good under Windows
- //import processing.video.*;
- //MovieMaker mm;
- //</EDIT> Movie
- int row;
- GPX gpx;
- SphericalMercator proj;
- float minx;
- float miny;
- float maxx;
- float maxy;
- int i;
- int j;
- int k;
- PGraphics pg;
- int kleur;
- void setup() {
- //<EDIT>: bounding box for the image/movie (in longitude (x) latitude (y))
- //amsterdam
- minx = 4.50;
- miny = 52.20;
- maxx = 5.2;
- maxy= 52.5;
- //</EDIT>
- //<EDIT>:Size of the image/movie
- size(1024,768);
- //</EDIT>
- double offX = 0;
- double offY = 49;
- frameRate(60);
- background(0);
- proj = new SphericalMercator();
- gpx = new GPX(this);
- i = 0;
- j= 0;
- k=0;
- pg = createGraphics(width, height, P2D);
- kleur = #3465a4;
- noFill();
- stroke(kleur);
- strokeJoin(ROUND);
- strokeWeight(2);
- smooth();
- //<EDIT>: Filename
- gpx.parse("Wilbert.gpx");
- //</EDIT>: Filename
- //<EDIT> Movie
- // mm = new MovieMaker(this, width, height, "drawing.mov", 60, MovieMaker.ANIMATION, MovieMaker.HIGH);
- //<EDIT>
- }
- void draw() {
- /*
- This bit of code creates an animation with all the tracks within the boundingbox set in the Setup()
- Note that tracks or track segments outside the view are still rendered and as such take time in the animation.
- To create a movie out of it, uncomment all the bits between to <Edit> Movie and </Edit> Movie
- */
- // <EDIT> Animation
- ///*
- background(0);
- pg.beginDraw();
- pg.stroke(kleur, 125);
- pg.strokeWeight(1.5);
- pg.smooth();
- pg.noFill();
- GPXTrack trk = gpx.getTrack(i);
- GPXTrackSeg trkseg = trk.getTrackSeg(j);
- pg.beginShape();
- GPXPoint pt = trkseg.getPoint(k);
- float[] c = proj.Project(pt.lon, pt.lat, minx, miny, maxx, maxy);
- pg.vertex((c[0]),(c[1]));
- GPXPoint pt2 = trkseg.getPoint(k+1);
- float[] c2 = proj.Project(pt2.lon, pt2.lat, minx, miny, maxx, maxy);
- pg.vertex((c2[0]),(c2[1]));
- pg.endShape();
- pg.endDraw();
- image(pg,0,0);
- stroke(kleur);
- ellipse(c2[0],c2[1],6,6);
- k++;
- // <EDIT> Movie
- // mm.addFrame();
- // </EDIT
- if (k == trkseg.size()-1) {
- k = 0;
- if (j<(trk.size()-1)){
- j++;
- }
- else {
- j =0;
- if(i<(gpx.getTrackCount()-1)){
- i++;
- }
- else {
- //<EDIT> Movie
- // mm.finish();
- //</EDIT>
- print("end");
- noLoop();
- }
- }
- }
- //*/
- // </EDIT> Animation
- /*
- This bit of code creates an image with all the tracks within the boundingbox set in the Setup()
- and saves it as tracks.png (unless you change the filename)
- */
- // <EDIT> Picture
- /*
- stroke(kleur,125);
- strokeJoin(ROUND);
- strokeWeight(1.5);
- for (i = 0; i < gpx.getTrackCount(); i++) {
- GPXTrack trk = gpx.getTrack(i);
- for (j = 0; j < trk.size(); j++) {
- GPXTrackSeg trkseg = trk.getTrackSeg(j);
- beginShape();
- for (k = 0; k < trkseg.size(); k++) {
- GPXPoint pt = trkseg.getPoint(k);
- float[] c = proj.Project(pt.lon, pt.lat, minx, miny, maxx, maxy);
- vertex((c[0]),(c[1]));
- }
- endShape();
- }
- }
- saveFrame("tracks.png");
- print("end");
- noLoop();
- */
- // </EDIT> Picture
- }
1