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
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.
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
Follow this Question
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