• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with arraylist  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a program for an assignment, and I have almost all of it working, but I just don't understand why the following code doesn't work, the error I get is:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.set(Unknown Source)
at NodeArray.loadGame(NodeArray.java:91)
at Test.main(Test.java:31)




It gives me the error when I try to run the program in the main class, at the line: "super.set(0, nodes[0]);" in the loadGame() method. Any hel pwould be appreciated!
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the javadoc for ArrayList.set method
Replaces the element at the specified position in this list with the specified element.

You don't have any elements in your ArrayList to start with, so you can't replace one. You need to add some elements to the ArrayList before you can use the set method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!