- Home /
IndexOutOfRangeException: Array index is out of range.
Ten times I run the program once will show me this error .........
IndexOutOfRangeException: Array index is out of range. dataLoader+c__Iterator0.MoveNext () (at Assets/1magazi/dataLoader.cs:193) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
in items[1] Can anyone help me with this ????
WWW itemsData = new WWW("http://magazi1.000webhostapp.com/magazi_1/Datas.php");
yield return itemsData;
// var items = new GameObject[20];
string itemsDataString = itemsData.text;
string[] items;
items = itemsDataString.Split(';');
yield return itemsData;
if (GetDataValue(items[1].ToString(), "situation:").ToString() == "free")
{
Table_1_mavro.enabled = true;
Table_1_redd2.enabled = false;
}
I would say itemsData.text doesn't have a semicolon splitting at least two string passages, but more likely is just empty. $$anonymous$$ake sure you get an actual string from the WWW call.
Answer by hassanyawar · Jun 22, 2017 at 08:17 AM
Maybe there is a possibility that 'items' array is getting null or 0 items. In that case accessing 'item[1]' will give this exception.
You should debug items = itemsDataString.Split(';');
and see what is it getting in the array.
And also you can add another check like:
if (items.Length > 0)
{
if (GetDataValue(items[1].ToString(), "situation:").ToString() == "free")
{
Table_1_mavro.enabled = true;
Table_1_redd2.enabled = false;
}
}
It will ensure that 'items' array is only accessed when it has been populated.
Your answer
Follow this Question
Related Questions
Change an objects Array position dynamiclly in a match 3 game 0 Answers
playing a different animation in an array 1 Answer
List gives "Array index is out of range" for no reason 2 Answers
Null first array index and shift rest by 1? 1 Answer
IndexOutOfRangeException: Array index is out of range. 0 Answers