Weird null pointer exception (XML feed)
in
Programming Questions
•
1 year ago
Dear all interested readers,
I have a problem with a few null pointer exceptions, comming from XML requests that should not give null pointer exceptions. When I check the data via a browser, there seems to be no problem.
If I change the line:
xml = new XML(this, "http://www.witregel.nl/scraper/getall.php?keyword[]=&keyword[]=assad");
to
xml = new XML(this, "http://www.witregel.nl/scraper/getall.php?keyword[]=&keyword[]=parijs");
I get a null pointer exception. When I check the link via my webbrowser, I can't find any reason to get an error. It all looks good. Do I miss something?
Thanks in advance for the tips.
Here's the code:
I have a problem with a few null pointer exceptions, comming from XML requests that should not give null pointer exceptions. When I check the data via a browser, there seems to be no problem.
If I change the line:
xml = new XML(this, "http://www.witregel.nl/scraper/getall.php?keyword[]=&keyword[]=assad");
to
xml = new XML(this, "http://www.witregel.nl/scraper/getall.php?keyword[]=&keyword[]=parijs");
I get a null pointer exception. When I check the link via my webbrowser, I can't find any reason to get an error. It all looks good. Do I miss something?
Thanks in advance for the tips.
Here's the code:
String woorden = " ";
boolean aan = false;
int startcount;
XML[] urls;
XML[] bron;
XML[] artikelen;
int scroll;
String[] wordsArray;
int numLines = 0;
float textHeight;
String artikel;
XML xml;
int i;
PFont font;
int fontSize = 10;
int specificWidth = 700-40;
int lineSpacing = 5;
void setup() {
size(1300, 800);
font = createFont("Arial", fontSize);
textFont(font, fontSize);
}
void draw() {
background(255);
xml = new XML(this, "http://www.witregel.nl/scraper/getall.php?keyword[]=&keyword[]=assad");
//xml = new XML(this, "http://www.witregel.nl/scraper/getall.php?keyword[]=&keyword[]=parijs");
XML[] urls = xml.getChildren("result/url");
XML[] bron = xml.getChildren("result/bron");
XML[] artikelen = xml.getChildren("result/artikel");
for (int i = 0; i < artikelen.length; i++)
{
textFont(font, fontSize);
if (frameCount % 1 == 0) {
float m = mouseX;
scroll = (int)map(m, 0, width, 0, artikelen.length);
println(scroll);
textFont(font, fontSize);
String artikel = artikelen[scroll].getContent();
artikel = artikel.replaceAll("\n", " ");
fill(0, 255, 0);
rect(60, 10, specificWidth+20, textboxhoogte(artikel, specificWidth, fontSize, lineSpacing));
if (scroll == i) {
fill(255);
}
else {
fill(0);
}
fill(0, 20, 300);
text( artikel, 70, 20, specificWidth, textboxhoogte(artikel, specificWidth, fontSize, lineSpacing));
fill(0, 0, 250);
textFont(font, 20);
}
}
}
int textboxhoogte(String string, int specificWidth, int fontSize, int lineSpacing) {
String[] wordsArray;
String tempString = "";
int numLines = 0;
float textHeight;
wordsArray = split(string, " ");
for (int i=0; i < wordsArray.length; i++) {
if (textWidth(tempString + wordsArray[i]) < specificWidth) {
tempString += wordsArray[i] + " ";
}
else {
tempString = wordsArray[i] + " ";
numLines++;
}
}
numLines++;
textHeight = numLines * (textDescent() + textAscent() + lineSpacing);
return(round(textHeight));
}
1