creating class, but suddenly have problem with xml in constructor, what's wrong?
in
Contributed Library Questions
•
6 months ago
Hi there,
I'm building a sketch with various subclasses, all based on pulling in various data streams. All work fine except this part that calls yahoo weather data. As I'm still a learner-driver and after a lot of puzzling I still can't figure out what the problem is.- It keeps tellng me "The constructor XMLRequest (weatherclass.WeatherClass( int, int) is undefined".
To try to solve it, I've simplefied the code just calling the weather data and visualising it as a dot. It works fine as a "classless" sketche. But if I try using a "class" I get the same remark. What am I doing wrong?
Is it the parameters in the constructor, it does not make a difference if I put none or 1 in there?
Here are both codes:
'classless':
------------------------------------------------------------------------------------------------------------------------------------
import simpleML.*;
int temperature;
int weather;
//-----------------------
void setup() {
size(200, 200);
smooth();
XMLRequest xreq = new XMLRequest(this, "http://weather.yahooapis.com/forecastrss?w=26360988&u=c");
xreq.makeRequest();
}
//-----------------------
void draw() {
background(255);
dotObject();
}
//--------------------
void getWeather() {
String url = "http://weather.yahooapis.com/forecastrss?w=26360988&u=c";
XMLRequest req = new XMLRequest(this, url);
req.makeRequest();
println ("loaded from xml.weather.yahoo.com");
}
void netEvent(XMLRequest ml) { // Get the specific XML content we want
temperature = int(ml.getElementAttributeText("yweather:condition", "temp"));
weather = int (ml.getElementAttributeText("yweather:condition", "code"));
}
//------------------------
void dotObject() {
fill (100);
ellipse (weather*2, temperature*2, weather, weather);
}
------------------------------------------------------------------------------------------------------------------------------------
with class:
------------------------------------------------------------------------------------------------------------------------------------
import simpleML.*;
WeatherClass dotObject;
//-------------------------------------
void setup() {
size(200, 200);
smooth();
dotObject = new WeatherClass (0,0);
}
//-----------------------------------
void draw() {
background(255);
dotObject.display();
}
//////////////////////////
class WeatherClass {
int x, y;
int temperature;
int weather;
//-----------------------------------
WeatherClass () {
XMLRequest xreq = new XMLRequest(this, "http://weather.yahooapis.com/forecastrss?w=26360988&u=c");
xreq.makeRequest();
}
void display() {
dot();
}
//-----------------------------------
void getWeather() {
String url = "http://weather.yahooapis.com/forecastrss?w=26360988&u=c";
XMLRequest req = new XMLRequest(this, url);
req.makeRequest();
println ("loaded from xml.weather.yahoo.com");
}
//-----------------------------------
void netEvent(XMLRequest ml) { // Get the specific XML content we want
temperature = int(ml.getElementAttributeText("yweather:condition", "temp"));
weather = int (ml.getElementAttributeText("yweather:condition", "code"));
}
//-----------------------------------
void dot () {
fill (255,0,0);
ellipse (weather*3, temperature*3, weather, weather);
}
}
------------------------------------------------------------------------------------------------------------------------------------
Thanks for your time, help and suggestions!
best
nanette
I'm building a sketch with various subclasses, all based on pulling in various data streams. All work fine except this part that calls yahoo weather data. As I'm still a learner-driver and after a lot of puzzling I still can't figure out what the problem is.- It keeps tellng me "The constructor XMLRequest (weatherclass.WeatherClass( int, int) is undefined".
To try to solve it, I've simplefied the code just calling the weather data and visualising it as a dot. It works fine as a "classless" sketche. But if I try using a "class" I get the same remark. What am I doing wrong?
Is it the parameters in the constructor, it does not make a difference if I put none or 1 in there?
Here are both codes:
'classless':
------------------------------------------------------------------------------------------------------------------------------------
import simpleML.*;
int temperature;
int weather;
//-----------------------
void setup() {
size(200, 200);
smooth();
XMLRequest xreq = new XMLRequest(this, "http://weather.yahooapis.com/forecastrss?w=26360988&u=c");
xreq.makeRequest();
}
//-----------------------
void draw() {
background(255);
dotObject();
}
//--------------------
void getWeather() {
String url = "http://weather.yahooapis.com/forecastrss?w=26360988&u=c";
XMLRequest req = new XMLRequest(this, url);
req.makeRequest();
println ("loaded from xml.weather.yahoo.com");
}
void netEvent(XMLRequest ml) { // Get the specific XML content we want
temperature = int(ml.getElementAttributeText("yweather:condition", "temp"));
weather = int (ml.getElementAttributeText("yweather:condition", "code"));
}
//------------------------
void dotObject() {
fill (100);
ellipse (weather*2, temperature*2, weather, weather);
}
------------------------------------------------------------------------------------------------------------------------------------
with class:
------------------------------------------------------------------------------------------------------------------------------------
import simpleML.*;
WeatherClass dotObject;
//-------------------------------------
void setup() {
size(200, 200);
smooth();
dotObject = new WeatherClass (0,0);
}
//-----------------------------------
void draw() {
background(255);
dotObject.display();
}
//////////////////////////
class WeatherClass {
int x, y;
int temperature;
int weather;
//-----------------------------------
WeatherClass () {
XMLRequest xreq = new XMLRequest(this, "http://weather.yahooapis.com/forecastrss?w=26360988&u=c");
xreq.makeRequest();
}
void display() {
dot();
}
//-----------------------------------
void getWeather() {
String url = "http://weather.yahooapis.com/forecastrss?w=26360988&u=c";
XMLRequest req = new XMLRequest(this, url);
req.makeRequest();
println ("loaded from xml.weather.yahoo.com");
}
//-----------------------------------
void netEvent(XMLRequest ml) { // Get the specific XML content we want
temperature = int(ml.getElementAttributeText("yweather:condition", "temp"));
weather = int (ml.getElementAttributeText("yweather:condition", "code"));
}
//-----------------------------------
void dot () {
fill (255,0,0);
ellipse (weather*3, temperature*3, weather, weather);
}
}
------------------------------------------------------------------------------------------------------------------------------------
Thanks for your time, help and suggestions!
best
nanette
1