Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: java.lang.IndexOutOfBoundsException  (Read 7144 times)

oranoron

  • Lieutenant
  • **
  • Posts: 85
    • View Profile
java.lang.IndexOutOfBoundsException
« on: December 01, 2013, 10:59:13 AM »

I started getting this crash after starting a new game all of a sudden when I last updated my mod. I can't figure out what started it. Prior to this I had been debugging an issue where the game was unable to locate ship variants that were clearly in my variants folder and when I resolved it this problem occurred. I don't know what it is trying to say.


Spoiler
22462 [Thread-6] ERROR com.fs.starfarer.combat.String  - java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
   at java.util.ArrayList.RangeCheck(ArrayList.java:547)
   at java.util.ArrayList.get(ArrayList.java:322)
   at com.fs.starfarer.loading.ShipNameStore.o00000(Unknown Source)
   at com.fs.starfarer.loading.ShipNameStore.o00000(Unknown Source)
   at com.fs.starfarer.campaign.fleet.FleetData.addFleetMember(Unknown Source)
   at com.fs.starfarer.campaign.fleet.CampaignFleet.addFleetMember(Unknown Source)
   at com.fs.starfarer.loading.FleetCreationSpec.super(Unknown Source)
   at com.fs.starfarer.campaign.CampaignEngine.createFleet(Unknown Source)
   at data.scripts.world.corvus.PirateSpawnPoint.spawnFleet(PirateSpawnPoint.java:43)
   at data.scripts.world.corvus.Corvus.generate(Corvus.java:55)
   at data.scripts.world.SectorGen.generate(SectorGen.java:61)
   at com.fs.starfarer.campaign.save.CampaignGameManager.o00000(Unknown Source)
   at com.fs.starfarer.title.OoOO.dialogDismissed(Unknown Source)
   at com.fs.starfarer.ui.float.dismiss(Unknown Source)
   at com.fs.starfarer.ui.impl.I.dismiss(Unknown Source)
   at com.fs.starfarer.campaign.save.H.actionPerformed(Unknown Source)
   at com.fs.starfarer.ui.privatesuper.super(Unknown Source)
   at com.fs.starfarer.ui.F.processInput(Unknown Source)
   at com.fs.starfarer.ui.OoOo.o00000(Unknown Source)
   at com.fs.starfarer.OoOO.øÒÒ000(Unknown Source)
   at com.fs.super.oOOO.Ò00000(Unknown Source)
   at com.fs.starfarer.combat.String.o00000(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)
[close]
Logged

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #1 on: December 01, 2013, 11:07:56 AM »

Well, that is an array index overflow, where something tries to access an index that is not in the array.

I suggest disabling all of your mods first. Then, enable one at a time, until it stops working. That should point to which mod is the problem.

Can't really help beyond that.
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

oranoron

  • Lieutenant
  • **
  • Posts: 85
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #2 on: December 01, 2013, 11:48:48 AM »

That doesn't really help as I already knew it was my mod causing the problem. The only thing I can find in the debug list is:

14299 [Thread-6] WARN  com.fs.starfarer.loading.SpecStore  - Description with id flarelauncher_fighter_SHIP_SYSTEM not found
14306 [Thread-6] WARN  com.fs.starfarer.loading.SpecStore  - Description with id traveldrive_SHIP_SYSTEM not found
14307 [Thread-6] WARN  com.fs.starfarer.loading.SpecStore  - Description with id inferniuminjector_SHIP_SYSTEM not found
14307 [Thread-6] WARN  com.fs.starfarer.loading.SpecStore  - Description with id skimmer_drone_SHIP_SYSTEM not found

But I have never used, references or even opened those files and they are where they should be.
Logged

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #3 on: December 01, 2013, 11:51:55 AM »

1 have you been fiddling around with the ship files at all?

2 als it could be you jusc corrupted your core files (ive done that once or twice before) so if 1 is false re install
Logged
BISO
(WIP) lots of shiny new weapons ( :-[ i have more weapons then sprites :-[ )

i got a cat pad
its like a mouse pad but better!

oranoron

  • Lieutenant
  • **
  • Posts: 85
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #4 on: December 01, 2013, 11:55:31 AM »

I've been working on my mod all morning specifically updating my ship files because I have been getting rid of the place holder graphics I was using on multiple ships and changing the files to have bound polygons and weapon slots that match the new graphics.
Logged

oranoron

  • Lieutenant
  • **
  • Posts: 85
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #5 on: December 01, 2013, 12:06:42 PM »

Well ***. I did a clean install and it seems I've lost my admins privileges somehow... No clue what's going on.

Oh and the problem is persisting even after the reinstall. It keeps saying it cannot find those 4 ship systems when they are sitting right in the correct folder after the fresh install.....

Additionally:

Whenever I try to move one of my mod files I keep being told another problem is using the file so the process fails. However I've disabled every program that could be using them...
« Last Edit: December 01, 2013, 12:16:18 PM by oranoron »
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #6 on: December 01, 2013, 03:46:52 PM »

indexOutOfBounds is caused when you're trying to do something on a List or other type of array-like object that has a size of 0 (i.e., there is nothing stored in that data object).

So, for example:

Code: java
List theseShips = engine.getAllShips()

for (int i = 0; i < theseShips.size(); i++)
{
  ShipAPI thisShip = (ShipAPI) theseShips.get(i);
  <do Stuff>
}

This can cause a crash, because it's going to try to cast to a zero-length list to (ShipAPI) and <do Stuff> on a zero-length List, both of which will obviously throw a Null Exception Error.

So, instead, there are two easy ways out:  Either write a if/then checker or use Iterator.hasNext(), which essentially does the same thing and is safer and easier in most cases.  

Examples:

Code: java
List theseShips = engine.getAllShips()

//Safety code around for-next loop
if(theseShips.size() > 0)
{
for (int i = 0; i < theseShips.size(); i++)
{
  ShipAPI thisShip = (ShipAPI) theseShips.get(i);
  <do Stuff>
}
}

//Using Iterator instead
for(Iterator shipsIter = theseShips.iterator(); shipsIter.hasNext(); )
{
  ShipAPI thisShip = (ShipAPI) shipsIter.next();
  <do Stuff>
}
« Last Edit: December 01, 2013, 03:48:47 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

oranoron

  • Lieutenant
  • **
  • Posts: 85
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #7 on: December 02, 2013, 07:07:55 AM »

Thanks a heap. It turns out it was my custom ship name list that was the source of the mysterious crashes.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #8 on: December 02, 2013, 12:23:46 PM »

Just a small additional note:

After doing some reading, it appears that there is pretty much zero reason not to use Iterator (although the way I wrote it there is not the "ideal" version, it's the version that Janino can compile). 

Using for-->next loop structures without using Iterator can cause various Bad Things to happen in certain contexts, especially where the data being checked might be changing in another thread.

For newbies, I think that using Iterator is probably the "best" way to code working through loops like these, and is almost certainly the safest- from what I've read, there is almost zero speed difference between that and simpler for-->next loop structures, while being a lot safer. 

Best is in quotes because I'm still learning the vagaries of Java and may have missed something important in my reading, but it would appear there's broad consensus about that :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

RawCode

  • Admiral
  • *****
  • Posts: 511
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #9 on: December 03, 2013, 09:30:18 PM »

 at data.scripts.world.corvus.PirateSpawnPoint.spawnFleet(PirateSpawnPoint.java:43)

open this like and add debug output before given line, debug output shoud println each param\field\object used at given line.

learn to debug, issue very easy to detect and fix.
Logged

Nick XR

  • Admiral
  • *****
  • Posts: 712
    • View Profile
Re: java.lang.IndexOutOfBoundsException
« Reply #10 on: September 08, 2016, 03:23:32 PM »

Replying to this since it was the first google search to come up when looking for "starsector java.lang.IndexOutOfBoundsException: Index: 0, Size: 0"

I had this same issue, turns out the problem was I was compiling the jar for my mod with a newer version of the JDK (1.8) than the game was running under (1.7).  I switched my JDK that compiles the mod to the same version as the game and everything works great now.