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 /
  • Help Room /
avatar image
0
Question by talaxet · May 21, 2016 at 03:16 PM · javascriptsplit

Why is this String.Split() giving a object reference not set error?

this is giving a Null reference exception: object reference not set to an instance of an object but i cant figure out why, the error is near the end where it declares variable line2 as an array of line.split

 #pragma strict
 import System.IO;
 var names = new Array ();
 var platforms = new Array ();
 var genres = new Array ();
 var styles = new Array ();
 var clients = new Array ();
 var gamePanel : GameObject;
 var gamePane : GameObject;
 var test : boolean;
 var line = "";
 
 function loadGameList ()
 {
     var sr : StreamReader = new System.IO.StreamReader(Application.dataPath + "/" + "games.list");
     var found = false;
     for(var i = 0; i < 15 || found == false; i++)
     {
         line = sr.ReadLine();
         if(line == "#")
         {
             found = true;
         }
         else
         {
             var line2 = line.Split(","[0]);  //this line is giving the error <----------
             addNewGame(line2[0],parseInt(line2[1]),parseInt(line2[2]),parseInt(line2[3]),parseInt(line2[4]));
         }
     }
     addGameList();
     sr.Close();
 }

i dont see anything wrong about var line2 = line.Split(","[0]);

so i really dont understand why its giving a null reference error

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by FortisVenaliter · May 21, 2016 at 03:17 PM

The only reason it would, would be if line is null. Try putting a Debug.Log in there to log line, and you'll know for sure.

Comment
Add comment · Show 1 · 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
avatar image talaxet · May 21, 2016 at 03:39 PM 0
Share

got the problem, the 15 is meant as a limit so it will only read 15 lines if the # to stop it isn't there but ins$$anonymous$$d off && there is || so it will read 15 lines regardless of if there's any info there so it will return a ton of null answers

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can i make an animation like csgo case opening? 2 Answers

How to make a player move up then forward using ontrigger enter collider? 0 Answers

Error BCE0051 with script JS 1 Answer

Help With Camera-Dependent 3rd Person Control 0 Answers

Top Down Game - Camera Follow Player and General Scripting Question 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