We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
XMLElement (Read 758 times)
XMLElement
Feb 4th, 2008, 5:09am
 
Code:

import processing.xml.*;
class XMLLoader {
XMLElement xml;

void XMLLoader( String fn ) {
size(200, 200);
xml = new XMLElement(this, fn);
int numSites = xml.getChildCount();
for (int i = 0; i < numSites; i++) {
XMLElement kid = xml.getChild(i);
int id = kid.getIntAttribute("id");
String url = kid.getStringAttribute("url");
String site = kid.getContent();
println(id + " : " + url + " : " + site);
}
}
void setup() {
noLoop();
XMLLoader x = new XMLLoader("12345.xml");
}



Fails with:



C:/DOCUME~1/h/LOCALS~1/Temp/build54766.tmp/Temporary_9333_7422.java:59:10:59:39:
Semantic Error: No applicable overload was found for a constructor with signature "XMLElement(Temporary_9333_7422.XMLLoader, java.lang.String)" in type "processing.xml.XMLElement". Perhaps you wanted the overloaded version "XMLElement(java.util.Hashtable $1, boolean $2);" instead?


C:/DOCUME~1/h/LOCALS~1/Temp/build54766.tmp/Temporary_9333_7422.java:74:15:74:40:
Semantic Error: No applicable overload was found for a constructor with signature "XMLLoader(java.lang.String)" in type "Temporary_9333_7422$XMLLoader". Perhaps you wanted the overloaded version "XMLLoader();" instead?
Re: XMLElement
Reply #1 - Feb 4th, 2008, 9:29am
 
First, if you want to create a constructor method don't provide a return value, i.e. also no void.

Second, "this" always refers to the current instance of the class you're in. The XMLElement constructor expects the applet, not your XMLLoader as first parameter.

So you should do something like this:

Code:

import processing.xml.*;

void setup() {
size(200, 200);
XMLLoader x = new XMLLoader(this, "12345.xml");
}

class XMLLoader {
XMLElement xml;

XMLLoader(PApplet applet, String fn ) {
xml = new XMLElement(applet, fn);
int numSites = xml.getChildCount();
for (int i = 0; i < numSites; i++) {
XMLElement kid = xml.getChild(i);
int id = kid.getIntAttribute("id");
String url = kid.getStringAttribute("url");
String site = kid.getContent();
println(id + " : " + url + " : " + site);
}
}
}
Page Index Toggle Pages: 1