Null reference exception in Lists

Hello, the error is a null reference exception on the AddRange line. It seems to think that something there, either the List or one of the items being added, reference is null. The second script is one from one of the items being added. This is quite a simple issue but I can’t pin down the cause. Can anyone offer advice or spot the probably obvious problem that I’m failing to see? I can offer more information if you should need to request it.


	public void deathRelist(GameObject nullShip)
		//find list with null ship and store
		List<GameObject> listWithNullShip = FindListContainingShip(nullShip);
		//create empty list for storage
		List<GameObject> newListForShips = null;
		//remove null ship from list
		//store remaining ships in new lists
		//clears and removes old list from master list
		//relists all ships in new list one ship at a time.
		foreach(GameObject ship in newListForShips)


	public void Destroy()
		if(canDestroy == true)
			Debug.Log ("Destroy called");
			//stores the ship which has been destroyed
			nullShip = this.gameObject;
			//resets parents reference variables
			this.transform.parent.GetComponent<GridSquare>().currentShip = null;
			this.transform.parent.GetComponent<GridSquare>().shipDisplay = null;
			this.transform.parent.GetComponent<GridSquare>().currentShipType = null;
			this.transform.parent.GetComponent<GridSquare>().isEmpty = true;
			//deparents ship from grid
			this.transform.parent = null;
			//gets reference for arraholder
			ArrayHolder scriptRef = reference1.GetComponent<ArrayHolder>();
			//Calls method to relist the ships in null ships list
			//Destroys this ship.


public void shipPlaced(int x, int y, GameObject gridShip, string gridShipType)
		List<GameObject> shipList; 
		bool adjacentShipFound = false;
		List<GameObject> lastListAddedTo = null;
		foreach(GameObject item in gridArray)  //Look at every spot in grid
			GridSquare currentSquare = item.GetComponent<GridSquare>();
			int x2,y2;
			//Read x2 y2 from item name
			x2 = currentSquare.X;
			y2 = currentSquare.Y;
			//check if currentSquare next to newly placed ship
			if(x2 == x+1 && y2 == y || x2 == x-1 && y2 == y || x2 == x && y2 == y+1 || x2 == x && y2 == y-1)
				//AND if it contains a ship of the same type
				if(currentSquare.currentShipType == gridShipType)
					//identified a ship which is adjacent to our newly placed ship
					GameObject adjacentShip = currentSquare.currentShip;
				 	//Find the list this found ship exists in already
					List<GameObject> matchingShipList = FindListContainingShip(adjacentShip);
					//Have we already found a matching list?
					if (adjacentShipFound == false)
						//Add newlyAddedShip to the matchingShipList
						lastListAddedTo = matchingShipList;
						adjacentShipFound = true;
						//Combine last list and matching list together

You are getting a null reference because your newListForShips list is in fact null. You set it with this line:

List<GameObject> newListForShips = null;

Change the line to this:

List<GameObject> newListForShips = new List<GameObject>();

This will instantiate your list so you can add to it.