NulklPointerException
in
Programming Questions
•
2 years ago
Hi,
I'm new to processing and am using it for a piece of coursework at university in order to visualise the weather feed from one of the university buildings.
Basically, when running my applet I am getting the following error:
- processing.app.debug.RunnerException: NullPointerException
- at processing.app.Sketch.placeException(Sketch.java:1543)
- at processing.app.debug.Runner.findException(Runner.java:583)
- at processing.app.debug.Runner.reportException(Runner.java:558)
- at processing.app.debug.Runner.exception(Runner.java:498)
- at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
- at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
- at processing.app.debug.EventThread.run(EventThread.java:89)
- Exception in thread "Animation Thread" java.lang.NullPointerException
- at coursework$BarGroup.convertToFloat(coursework.java:154)
- at coursework$BarGroup.<init>(coursework.java:123)
- at coursework.setup(coursework.java:46)
- at processing.core.PApplet.handleDraw(PApplet.java:1583)
- at processing.core.PApplet.run(PApplet.java:1503)
- at java.lang.Thread.run(Thread.java:680)
- import processing.xml.*;
- class BarGroup
- {
- XMLElement[] feed;
- float[] data = convertToFloat(feed);
- Bar[] group = new Bar[3];
- float highestNumber = highestValue(data);
- // COnstructor
- BarGroup ( XMLElement[] xmlValue, int xPos)
- {
- feed = new XMLElement[xmlValue.length];
- feed = xmlValue;
- // Color, height, new height, xpos
- group[0] = new Bar(color(0, 055, 0), 0, map(data[0], 0, highestNumber, 0, 350), xPos);
- group[1] = new Bar(color(0, 120, 0), 0, map(data[1], 0, highestNumber, 0, 350), (xPos + 10));
- group[2] = new Bar(color(0, 255, 0), 0, map(data[2], 0, highestNumber, 0, 350), (xPos + 20));
- }
- // Show the group of Bars
- void display()
- {
- for (int i = 0; i < 3; i++)
- {
- group[i].display();
- }
- }
- // Turn the XMLElement into an Array of Floats
- float[] convertToFloat( XMLElement[] toConvert )
- {
- String numberOne = toConvert[0].getContent();
- String numberTwo = toConvert[1].getContent();
- String numberThree = toConvert[2].getContent();
- println(numberOne);
- println(numberTwo);
- println(numberThree);
- float[] returnValues = new float[3];
- returnValues[0] = float(numberOne);
- returnValues[1] = float(numberTwo);
- returnValues[2] = float(numberThree);
- return returnValues;
- }
- // Find the biggest number
- float highestValue( float numberRange[] )
- {
- float number = 0;
- if ( numberRange[0] > numberRange[1] && numberRange[0] > numberRange[2] )
- {
- number = numberRange[0];
- }
- else if ( numberRange[1] > numberRange[0] && numberRange[1] > numberRange[2])
- {
- number = numberRange[1];
- }
- else if ( numberRange[2] > numberRange[0] && numberRange[2] > numberRange[1])
- {
- number = numberRange[2];
- }
- return number;
- }
- }
Your time is much appreciated,
Daniel Groves.
1