FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Array problem
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Array problem  (Read 1425 times)
pinkwalker

WWW Email
Array problem
« on: Feb 5th, 2005, 12:03am »

Hey!, i'm writting this piece of code.  
In it when i receive the string packet for carnivore and parse i will use some little pieces as variables.
 
I get this error:
 
Error while running applet.  
java.lang.ArrayIndexOutOfBoundsException: 1
 at Temporary_1383_4679.loop(Temporary_1383_4679.java:37)
 at BApplet.nextFrame(BApplet.java:49
 at BApplet.run(BApplet.java:42
 at java.lang.Thread.run(Thread.java:536)
 
when compile my code. Any one can help me?
 
Here's my code:
 
//code:
 
//for p5 69
//
/////carnivore
Socket socket;
BufferedReader packetreader;
CarnivoreListener CL;
String packet;
String packet_datestamp;
 
////////mis variables
String cut;
int ipDe1;
int ipDe2;
int ipDe3;
int ipPara1;
int ipPara2;
int ipPara3;
int puerto1;
int puerto2;
 
void setup(){
 
  //start listening to carnivore
  CL = new CarnivoreListener();
  CL.startListening();
 
}
 
void loop(){
 
  packet = CL.getPacket();
 
 
  String lista[] = split (packet,'.');
 
  /////////  ip de
  ipDe1 = Integer.parseInt(lista[1]);
  ipDe2 = Integer.parseInt(lista[2]);
  ipDe3 = Integer.parseInt(lista[3]);
 
  //////// ip para
  String ip6 [] = split(lista[6]);
  ipPara1 = Integer.parseInt(ip6[2]);
  ipPara2 = Integer.parseInt(lista[7]);
  ipPara3 = Integer.parseInt(lista[8]);
 
  /////// puerto de
  puerto1 = Integer.parseInt(ip6[0]);
  String p2 [] = split(lista[10]);
  puerto2 = Integer.parseInt(p2[0]);
 
(...)
 

***************
www.pinkwalker.tk
Ricard


Re: Array problem
« Reply #1 on: Feb 5th, 2005, 3:12am »

Hola,
 
You must have in mind that arrays indexes go from 0 to the (length of the array)-1.
 
I see that in your code, you are not using lista[0].  I don't know if that is in purpose or not, but if the lista[] array has 10 elements lista[10] will give you an OutOfBounds errors.
 
This might not be the error, in that case, an example of the value of the variable 'packet' could help in solving the problem.
 
Espero que te sirva de ayuda,
ricard
 
fjen

WWW
Re: Array problem
« Reply #2 on: Feb 5th, 2005, 3:41pm »

let me add to ricards post, you can check if lista is set and what size it has like this:
 
Code:
if (lista != null && lista.length >= 10)
{
  /*ok*/
}

/F
 
pinkwalker

WWW Email
Re: Array problem
« Reply #3 on: Feb 7th, 2005, 12:53pm »

Thanks a lot!!!
Gracias!
 
 

***************
www.pinkwalker.tk
Pages: 1 

« Previous topic | Next topic »