title: Class Not Found Exception on Class.forName()
body: <p>I started reading &quot;Java Game Development with LibGDX&quot; and I'm building a <a href="https://github.com/Apress/java-game-dev-LibGDX/tree/master/Ch02%20Starfish%20Collector" rel="nofollow noreferrer">game</a>, which is explained step by step in chapter 3 of the book. The player controls a turtle, avoiding rocks and captures starfish.
  I'm using intellij (instead of blueJ, recommend by the book) and java8.</p>
  <p>To explain the problem. The <a href="https://github.com/Apress/java-game-dev-LibGDX/blob/master/Ch03%20Starfish%20Collector/BaseActor.java" rel="nofollow noreferrer">BaseActor</a>  Class has a method &quot;ArrayList getList&quot; which creates a list for each type of actor(which can be found in the <a href="https://github.com/Apress/java-game-dev-LibGDX/blob/master/Ch03%20Starfish%20Collector/StarfishCollector.java" rel="nofollow noreferrer">StarfishCollecor</a>, which are 4 Rocks actors and 4 Starfish actors. The output should be 2 actor lists. The Rock list is created no problem, but the starfish list generates a error:
  java.lang.ClassNotFoundException: Starfish</p>
  <p>Can I do this different? Yes, but this code will be reused later in the book, so I like to solve the problem using this method.</p>
  <p>I looked around the internet and I found a <a href="https://gamedev.stackexchange.com/questions/182847/class-not-found-exception-on-class-forname/186842?noredirect=1#comment337149_186842">post</a> (Class Not Found Exception on Class.forName()), asking the same question I have and the person seems to have found the solution.</p>
  <p>S/he says the  For each loop was getting out of bounds for the Starfish class and did a little null checking. But I don't understand how the For each loop gets out of bound or what s/he means with null checking.
  Please check the code in the <a href="https://gamedev.stackexchange.com/questions/182847/class-not-found-exception-on-class-forname/186842?noredirect=1#comment337149_186842">post</a>. And if you can explain the solution in a way a simple beginner like me can underhand, you would help be out a lot.</p>
  <p><a href="https://i.stack.imgur.com/Ru1U0.png" rel="nofollow noreferrer">game file hierarchy visual</a></p>
  <p>Lastly I put a prinln in the getList method to check how the method is building the list. The method is checking for actors in the MainStage and only grabbing the ones with the name &quot;Rock&quot; and later again for &quot;Starfish&quot;.
  At the end the action is repeating, but I dont understand why that is.
  If feel this is were thinks get out of hand.</p>
  <p>BaseActor index: BaseActor || list size: 0 || BaseActor list: []</p>
  <p>BaseActor index: Starfish  || list size: 0 || BaseActor list: []</p>
  <p>BaseActor index: Starfish  || list size: 0 || BaseActor list: []</p>
  <p>BaseActor index: Starfish  || list size: 0 || BaseActor list: []</p>
  <p>BaseActor index: Starfish  || list size: 0 || BaseActor list: []</p>
  <p>BaseActor index: Rock      || list size: 1 || BaseActor list: [Rock]</p>
  <p>BaseActor index: Rock      || list size: 2 || BaseActor list: [Rock, Rock]</p>
  <p>BaseActor index: Rock      || list size: 3 || BaseActor list: [Rock, Rock, Rock]</p>
  <p>BaseActor index: Rock      || list size: 4 || BaseActor list: [Rock, Rock, Rock, Rock]</p>
  <p>BaseActor index: Turtle    || list size: 4 || BaseActor list: [Rock, Rock, Rock, Rock]</p>
  <p>BaseActor index: BaseActor || list size: 0 || BaseActor list: []</p>
  <p>BaseActor index: Starfish  || list size: 1 || BaseActor list: [Starfish]</p>
  <p>BaseActor index: Starfish  || list size: 2 || BaseActor list: [Starfish, Starfish]</p>
  <p>BaseActor index: Starfish  || list size: 3 || BaseActor list: [Starfish, Starfish, Starfish]</p>
  <p>BaseActor index: Starfish  || list size: 4 || BaseActor list: [Starfish, Starfish, Starfish, Starfish]</p>
  <p>BaseActor index: Rock      || list size: 4 || BaseActor list: [Starfish, Starfish, Starfish, Starfish]</p>
  <p>BaseActor index: Rock      || list size: 4 || BaseActor list: [Starfish, Starfish, Starfish, Starfish]</p>
  <p>BaseActor index: Rock      || list size: 4 || BaseActor list: [Starfish, Starfish, Starfish, Starfish]</p>
  <p>BaseActor index: Rock      || list size: 4 || BaseActor list: [Starfish, Starfish, Starfish, Starfish]</p>
  <p>BaseActor index: Turtle || list size: 4 || BaseActor list: [Starfish, Starfish, Starfish, Starfish]</p>