Problems with IndexOutOfBoundsException

  • Themenstarter Themenstarter polishjazz
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
P

polishjazz

Gast
A help in German language can be very helpful too! 🙂

I'm using a standard applet from samples delivered with the Java Developer Kit, called GraphLayout... It's an easy-to-use network building tool (all you have to do is add values to 'edges' parameter in the HTML code). But I've noticed that if I exceed a certain number of connections, the applet doesn't work. The status bar of the browser says something like that:

Code:
exception java.lang.Array.IndexOutOfBounds.Exception

What could be the problem? How to solve it?

You can take a look at the page www.postdigital.nl/javaproblem to see what I mean or just download the .zip file with all java/html files in it.

I would be very grateful for your help!

edit deathbyaclown: changed to an adequate title
 
i did not read your sources, but nevertheless: an arrayindexoutofboundsexception usually occurs if you are accessing an element of an array, which does not exist.

e.g.:

Code:
int[] numbers = new int[5];

...

int sum = 5 + numbers[10];
 
Code:
    int findNode(String lbl) {
	for (int i = 0 ; i < nnodes ; i++) {
	    if (nodes[i].lbl.equals(lbl)) {
		return i;
	    }
	}
	return addNode(lbl);
    }

Thats the problem. I dont know how or if you modified the string you transfer to the applet. But this little method checks if a node is already present and if not, it creates a new node (Node = String in the paramter, like "bath" for example). But if you add more then 100 different Nodes to the Array

Code:
Node nodes[] = new Node[100];

You applet crashes with a ArrayIndexOutOfBoundsException because it tries to create a nodes[101];
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben