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.
IndexProgramming Questions & HelpSyntax Questions › comparing strings with strings
Page Index Toggle Pages: 1
comparing strings with strings (Read 722 times)
comparing strings with strings
Jul 21st, 2009, 5:52pm
 
Hi.
I've got a problem comparing strings with strings. I get an out of bounds exception with the following code (executed in the draw loop). it prints out tmpFeel before it crashes.
Code:
for(int n = 0; n < feelings.length; n++)
{
String tmpFeel = (String) feelings[n];
println(tmpFeel);
if(tmpFeel.equals("good"))
{
}
}

feelings.size = 5000+ items.

What went wrong?
Re: comparing strings with strings
Reply #1 - Jul 21st, 2009, 8:27pm
 
There's nothing wrong with this code, and it works perfectly fine when I try to run it. Does the IDE highlight any code when the exception is thrown? It may not be this part of the code that is your problem. Maybe post some more of the code so we can try and track it down.
Re: comparing strings with strings
Reply #2 - Jul 21st, 2009, 8:57pm
 
the sourcecode is a little too long to post it here I guess... you can download it here.
http://www.fishnation.de/processing/_2009_07_21_twitter_multithreaded.zip
Re: comparing strings with strings
Reply #3 - Jul 22nd, 2009, 7:36am
 
OK, I looked through your source, and the original code you posted looks to be working fine. However, I did find this area of interest within your main sketch:

In your activateMode() function, you call this:
Code:

for(int o = 0; o < 110; o++)
{
...
text(feelings[o], 145 + o * 40, (height/2) - 20);
println(o + " " + feelings[o] + " " + feelingCountDesc[o]);
...


I may have missed something, but from a glance it seems as if you initialize feelings to "= new String[1];", then you expand() it later to "expand(feelings, feelings.length + 1);". So by my count, the size of feelings is only [2], and yet in the above code, you are incrementing the variable "int o" all the way up to 109, which means you are way out of bounds when trying to call "feelings[o]."  

Again, I looked at the code quickly, so maybe you add 108 items to feelings[] somewhere along the way. But if not, that's what's causing your OB exception.
Re: comparing strings with strings
Reply #4 - Jul 25th, 2009, 9:50am
 
thanks for having a look at my code. I add new items into the array by calling loadFeelingFile() in setup(). This function loads new items from an external text file.
Page Index Toggle Pages: 1