ArguentOutOfRangeException: Argument is out of range. Parameter name:index

Hi, up until recently I had some code that was working fairly well. I’m not sure what I did, but now it’s throwing an ArgumentOutOfRangeException and I have no idea what is causing it. Can anyone help me?

using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;

public class SearchMap : MonoBehaviour {
	public float tagPercent = 80;
	private float inputRatio;
	private int q;
	private int b;
	private locationDatabase database;
	public List<Location> seenLocations = new List<Location>();
	public List<Location> newLocations = new List<Location> ();
	private List<Location> savedLocations = new List<Location> ();
	public List<string> tagList = new List<string> ();
	public string[] tagArray;
	public GameObject locListItem;
	public GameObject viewContent;
	public GameObject locMenu;
	public GameObject spawnItem;
	public GameObject curPip;
	public Transform pipHolder;
	public InputField iField;
	public string myName;
	public string tinyTag;
	public string[] tags;
	openLocation oLocation;
	public Sprite bluePip;
	public Sprite redPip;
	private bool tagLength;
	


	public void bounceName()
	{

		foreach(Transform child in pipHolder)
		{
			child.gameObject.SetActive(false);
		}
		myName = iField.text.ToLower ();

		foreach (Transform child in viewContent.transform) 
		{
			Destroy (child.gameObject);
		} 
		foreach (Location loc in database.locations) 
		{
			tagLength = false;
			tagArray = database.locations**.locTags.Split(',');**

** q = 0;**
** foreach(string tag in tagArray)**
** {**
__ if(tagArray[q].Contains(myName) && (myName.Length * 1f)/(tagArray[q].Length * 1f) >= tagPercent/100)__
** {**
** Debug.Log(tagArray[q]);**
** tagLength = true;**
** break;**
** }**
** q++;**
** }**
** Debug.Log(“before suspect”);**
__ Debug.Log(database.locations**);__
if ((!seenLocations.Contains (database.locations )) && savedLocations.Contains (database.locations ) && tagLength)
__ {
seenLocations.Add (database.locations );
Debug.Log("Added: " + seenLocations);
b++;
}**__

else if ((!seenLocations.Contains (database.locations )) && !savedLocations.Contains (database.locations ) && tagLength)
** {**
__ newLocations.Add (database.locations );
Debug.Log("Added: " + newLocations**);
b++;
}
else**

** {
b++;
Debug.Log(“Went to C Round”);
}
Debug.Log(“Stuck at end of part I”);
}
Debug.Log (“Made it end of part I”);
b = 0;
foreach (Location loc in newLocations) {
Debug.Log(“In part 2”);
spawnItem = Instantiate (locListItem) as GameObject;
spawnItem.transform.SetParent (viewContent.transform, false);
spawnItem.transform.localPosition = new Vector3 (100, -39 - (70 * b), 0);
oLocation = spawnItem.GetComponent ();**__

__ oLocation.locName = newLocations .locName;
oLocation.locAddress = newLocations .locAddress;
oLocation.locDescription = newLocations .locInfo;
oLocation.locScene = newLocations**.locScene;
oLocation.pipNumber = (b + 1).ToString();
oLocation.newPip = true;
oLocation.locMenu = locMenu;**__

__ curPip = pipHolder.FindChild(newLocations**.locName).gameObject;
curPip.gameObject.transform.GetComponent ().sprite = redPip;
curPip.transform.GetChild(0).GetComponent().text = (b + 1).ToString();
curPip.transform.GetComponent().listButton = spawnItem;
curPip.SetActive(true);**__

** b++;**
** }**
** b = 0;**
** foreach (Location loc in seenLocations) {**

** spawnItem = Instantiate (locListItem) as GameObject;**
** spawnItem.transform.SetParent (viewContent.transform, false);**
__ spawnItem.transform.localPosition = new Vector3 (100, -39 - (70 * (b + newLocations.Count)), 0);
** oLocation = spawnItem.GetComponent ();**__

__ oLocation.locName = seenLocations .locName;
oLocation.locAddress = seenLocations .locAddress;
oLocation.locDescription = seenLocations .locInfo;
oLocation.locScene = seenLocations**.locScene;
oLocation.pipNumber = (b + 1).ToString();
oLocation.newPip = false;
oLocation.locMenu = locMenu;**__

__ curPip = pipHolder.FindChild(seenLocations**.locName).gameObject;
curPip.gameObject.transform.GetComponent ().sprite = bluePip;
curPip.transform.GetChild(0).GetComponent().text = (b + 1).ToString();
curPip.transform.GetComponent().listButton = spawnItem;
curPip.SetActive(true);**__

** b++;**

** }**

** b = 0;**
** foreach (Location loc in seenLocations) {**
__ savedLocations.Add (seenLocations );
** b++;
}
seenLocations.Clear();**__

** b = 0;**
** foreach (Location loc in newLocations) {**
__ savedLocations.Add (newLocations );
** b++;
}
newLocations.Clear();**__

** }**

** //Debug.Log (myName);**

** void Start()**
** {**
** database = GetComponent ();**
** }**

}
The locations themselves just hold a bunch of strings, the last of which is a list of tags the player can search for, separated by commas. Here’s the full error:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List1[Location].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)**</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**SearchMap.bounceName () (at Assets/Scripts/testing/SearchMap.cs:75)**__</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:149)**__</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:626)**__</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:766)**__</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>**UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:54)**</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)**__</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)**__</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)**__</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong> <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>__**UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()__

That’s a lot of code and not much detail on the problem. You need to post the full error message so we have some idea where the error is in the posted code…