How to fix NullPointerException

edited May 2015 in How To...
float easing = 0.05;
float offset = 0;
void setup() {
size(720, 480);
bot1 = loadShape("robot1.svg");
bot2 = loadShape("robot2.svg");
bot3 = loadShape("robot3.svg");
landscape = loadImage("alpine.png");
 smooth();
//****CLASS**** Add the media files according the books instruction to make this application work.
//****CLASS**** Change Landscape Image to anyting of your choice, but it should be of the same type (.png) and roughly the same size.
//****CLASS**** When you get it working, snip a screen shot of it running and send the screen shot to the instructor. Don't send the .pde file.

landscape = loadImage("alpine.png");
smooth();
}
void draw() {
// Set the background to the "landscape" image; this image
// must be the same width and height as the program
background(landscape);
// Set the left/right offset and apply easing to make
// the transition smooth
float targetOffset = map(mouseY, 0, height, -40, 40);
offset += (targetOffset - offset) * easing;
// Draw the left robot
shape(bot1, 85 + offset, 65);
// Draw the right robot smaller and give it a smaller offset
float smallerOffset = offset * 0.7;
shape(bot2, 510 + smallerOffset, 140, 78, 248);
// Draw the smallest robot, give it a smaller offset
smallerOffset *= -0.5;
shape(bot3, 410 + smallerOffset, 225, 39, 124);
}

Answers

  • 1) Edit post. 2) Select code. 3) Press Ctrl + o.

  • 4) post the complete exception, with line number

  • robot1.svg does not exist or could not be read java.lang.NullPointerException at processing.data.XML$1.read(XML.java:190) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at processing.data.XML.(XML.java:187) at processing.core.PApplet.loadXML(PApplet.java:6322) at processing.core.PApplet.loadXML(PApplet.java:6312) at processing.core.PGraphicsJava2D.loadShape(PGraphicsJava2D.java:1537) at processing.core.PGraphicsJava2D.loadShape(PGraphicsJava2D.java:1526) at processing.core.PApplet.loadShape(PApplet.java:11651) at Robot_4_HW_Week_12.setup(Robot_4_HW_Week_12.java:27) at processing.core.PApplet.handleDraw(PApplet.java:2361) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source)

  • sorry about that.

  • It's saying it can't find robot1.svg. Have you followed the class instructions and put the media files where the book says to?

  • yes i did bilmor

  • That code looks wrong. The variables you use on lines 5-8 aren't defined anywhere. And lines 14 and 15 are repeats.

    Pictures should go in a folder called 'data' under the sketch folder and the filenames must match exactly - case is important

  • (Also, pressing ctrl-t in the processing editor will indent the code nicely)

Sign In or Register to comment.