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
HtmlParser (Read 982 times)
HtmlParser
Nov 30th, 2009, 7:54am
 
Hello

I'am trying to use some values that I get returned from the Html Parser.
Iam fetching the number of comments and it is stored in  s, which should be an ArrayList.

Printing the values from "s" shows up just fine and in a neat little list.
But when Iam trying to use this to specify the size of a sphere with this is just says. "The Type of the expression must be an array type but it resolved to ArrayList"


What Iam I doing wrong ?
Any help would be appreciated since Iam very confused about this and just cant get it to work.


Code:



import processing.net.*;
import org.htmlparser.*;
import org.htmlparser.util.*;
import org.htmlparser.filters.*;
import org.htmlparser.nodes.*;

Client c;
String data;

// variables to navigate the generated data structure
int nrofnodes = 0;

ArrayList elements = new ArrayList();
ArrayList parents = new ArrayList();
ArrayList l = new ArrayList();
ArrayList s = new ArrayList();

int nodesAdded = 0;
int maxDegree = 0;

// Simply point to a site on your own server that gets the html from any other site.
private String urlPath = "TheWebsiteUrlwhichIcouldntIncludeinThepost";
private String content;


void setup() {
 size(600, 400, P3D);
 background(50);
 fill(200);
 smooth();
 this.getDataFromClient();

 for (int i = 0; i < nrofnodes; i++)
 {

   if (((TagNode)elements.get(i)).getTagName().equals("A"))
   if (((LinkTag)elements.get(i)).getLinkText().indexOf("Comments") > 0)
   
   {
     String s = ((LinkTag)elements.get(i)).getLinkText() ;
     int temp = s.indexOf("Comments");
     s = s.substring(0 , temp-1);
     s = s.replace("1,","1");
     
     int nrofcom = Integer.valueOf( s );
     // l.add(new temp(nrofcom, l));
     String l = ((LinkTag)elements.get(i)).getLink() ;
     println(s+" "+l);

   }
 }
}


void draw() {
translate(60,60,0);
sphere(s[1]);
}






Re: HtmlParser
Reply #1 - Nov 30th, 2009, 8:58am
 
two things

ArrayList s = new ArrayList(); // s defined as a global arraylist
...
String s = ((LinkTag)elements.get(i)).getLinkText() ; // s defined as a string within setup

these two s variables are different things. you aren't storing those values in the global one, only the local one, which will disappear outside of setup. (it might be an idea to use a naming scheme that makes it obvious that global variables are global).

then there's this

sphere(s[1]); // s used within draw

sphere() expects a float, not a string and not an arraylist. if the values you read look like floating point numbers then you can convert then to floats easily enough (Float.valueOf(string)?).
Re: HtmlParser
Reply #2 - Nov 30th, 2009, 9:28am
 
Beside, you don't access members of ArrayList with the [] notation...
Page Index Toggle Pages: 1