Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mang-62 · May 20, 2017 at 08:48 AM · arrayindex

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;
     }
    







Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nt314p · Jun 22, 2017 at 12:39 AM 0
Share

Check if the array is null.

avatar image hexagonius nt314p · Jun 22, 2017 at 08:25 AM 0
Share

Its not, it's empty.

avatar image hexagonius · Jun 22, 2017 at 08:26 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges